Last active
May 12, 2023 07:26
-
-
Save TGITS/8d747a11a87eb1d5df90e4dfb0385c0a to your computer and use it in GitHub Desktop.
Tableau de fréquences avec groupingBy et counting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A exécuter avec JBang : jbang frequencies-map-with-groupingby-and-counting.jsh | |
* <p> | |
* Ou ouvrir dans JShell : /open frequencies-map-with-groupingby-and-counting.jsh | |
*/ | |
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; | |
List<String> daysOfWeek = List.of("Friday", "Thursday", "Thursday", "Saturday", "Thursday", "Thursday", "Monday", "Saturday", "Friday", "Saturday"); | |
Map<String, Long> frequencies = daysOfWeek.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); | |
frequencies.entrySet().iterator().forEachRemaining(System.out::println); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment