Created
October 29, 2020 13:55
-
-
Save iamitshri/d1aef56fed5634ba622d66602bfd0ad2 to your computer and use it in GitHub Desktop.
Java Streams Beauty
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
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