Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TGITS/8d747a11a87eb1d5df90e4dfb0385c0a to your computer and use it in GitHub Desktop.
Save TGITS/8d747a11a87eb1d5df90e4dfb0385c0a to your computer and use it in GitHub Desktop.
Tableau de fréquences avec groupingBy et counting
/**
* 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