... corresponding Long value is the number of occurrences of that word. The pipeline performs the following tasks:
-
Line 18 calls
Filesmethodlines(added in Java SE 8) which returns aStream<String>that reads lines of text from a file and returns each line as aString. ClassFiles(packagejava.nio.file) is one of many classes throughout the Java APIs which provide methods that returnStreams.
-
Line 19 uses
StreammethodflatMapto break each line of text into its separate words. MethodflatMapreceives aFunctionthat maps an object into a stream of elements. In this case, the object is aStringcontaining words and the result is aStream<String>for the individual words. The lambda in line 19 passes theStringrepresenting a line of text to ...