Java Stream for Coding Interview
Both practical and challenging, don’t skip this topic
Why Java Stream?
Stream is one of the best improvement in Java 8 compared with Java 7. But some of its API, are complicated and hard to understand, especially those of Collector and those for reduction.
I dare say that even experienced Java Stream users may still find them intimidating. Despite having using it for several years and having prior experience with Stream-like operations in other programming languages, I still occasionally find some Stream-related tasks challenging.
For those used to the ‘old’ ways of iterating through collections, devising solution in Stream operations do not come easy. Because Stream is the preferred way of processing collections nowadays, the stress-inducing Stream problems should not be dismissed as unnecessary but are actually realistic and should be expected at works.
These circumstances make Stream a useful tool in designing interview questions.
Sample #1: Find all distinct characters
Given a sentence comprising of one or multiple words separated by space (e.g.
java
,Hello World
,aadsbbaba
), return a sorted list of distinct characters excluding space. Solve this problem using…