Distinct elements in Java 8 streams
Finding the distinct elements of a Java stream is easy. We can use the distinct method:
List words = Arrays.asList("hello", "Java8", "world!", "hello);
List distinctWords = words.stream()
.distinct()
.collect(Collectors.toList()); // ["hello", "Java8", "world!"]
The first part of the code example filters the non-empty strings and counts