... corresponding Long
value is the number of occurrences of that word. The pipeline performs the following tasks:
-
Line 18 calls
Files
methodlines
(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 returnStream
s.
-
Line 19 uses
Stream
methodflatMap
to break each line of text into its separate words. MethodflatMap
receives aFunction
that maps an object into a stream of elements. In this case, the object is aString
containing words and the result is aStream<String>
for the individual words. The lambda in line 19 passes theString
representing a line of text to ...
Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.