Skip to content

Instantly share code, notes, and snippets.

@iamitshri
Created October 29, 2020 13:55
Show Gist options
  • Save iamitshri/d1aef56fed5634ba622d66602bfd0ad2 to your computer and use it in GitHub Desktop.
Save iamitshri/d1aef56fed5634ba622d66602bfd0ad2 to your computer and use it in GitHub Desktop.
Java Streams Beauty
Stream.of("Bob hit a ball, the hit BALL flew far after it was hit.".split("\\W"))
.filter(a->!a.trim()
.isEmpty())
.map(a -> a.trim().toLowerCase())
.filter(s ->!s.equals("hit"))
.collect(Collectors.groupingBy(Function.identity(),Collectors.counting()))
.entrySet()
.stream()
.max(Comparator.comparing(a->a.getValue()))
.get();
-- answer ball=2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment