Skip to content

Instantly share code, notes, and snippets.

@HomoEfficio
Created August 16, 2020 02:08
Show Gist options
  • Save HomoEfficio/221baf76513e92ca8638933fe7f676e3 to your computer and use it in GitHub Desktop.
Save HomoEfficio/221baf76513e92ca8638933fe7f676e3 to your computer and use it in GitHub Desktop.
Map.Entry<String, Long> mostCommonEntry =
List.of("나 혼자 길을 걷고", "나 혼자 티비 보고", "나 혼자 취해보고", "이렇게 매일 울고 불고")
.stream()
.map(s -> s.split(" "))
.flatMap(Arrays::stream)
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()))
.entrySet().stream()
.min(Map.Entry.comparingByValue(Comparator.reverseOrder()))
.orElseThrow(() -> new RuntimeException("no entry error"));
System.out.println(mostCommonEntry.getKey() + ": " + mostCommonEntry.getValue());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment