Created
May 12, 2023 08:21
-
-
Save TGITS/433b4a4d92fc14e719de4ac88eb7ef87 to your computer and use it in GitHub Desktop.
Tableau de fréquences avec groupingBy et summingInt
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-summingint.jsh | |
* <p> | |
* Ou ouvrir dans JShell : /open frequencies-map-with-groupingby-and-summingint.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, Integer> frequencies = daysOfWeek.stream().collect(Collectors.groupingBy(Function.identity(), Collectors.summingInt(element -> 1))); | |
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