Last active
October 13, 2017 03:02
-
-
Save qianyan/c68b8f188f0fd17193e46a294157fd31 to your computer and use it in GitHub Desktop.
implement frequency and unique? in java8
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
// frequency | |
Stream.of("a", "a", "b", "c").collect(toMap(identity(), a -> 1, (a, b) -> a + b)); | |
Stream.of("a", "a", "b", "c").collect(groupingBy(identity(), counting())); | |
Stream.of("a", "a", "b", "c").collect(groupingBy(identity(), summingInt(v -> 1))); | |
Stream.of("a", "a", "b", "c").collect(groupingBy(identity(), mapping(identity(), summingInt(v -> 1)))); | |
-> {a=2, b=1, c=1} | |
// unique? | |
frequency().values().stream().anyMatch(c -> c > 1); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment