... into its separate words. Method
flatMap
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 toPattern
methodsplitAsStream
(added in Java SE 8), which uses the regular expression specified in thePattern
(line 14) to tokenize theString
into its individual words. The result of line 19 is aStream<String>
for the individual words in all the lines of text. (This lambda could be replaced with the method referencepattern::splitAsStream
.)Lines 20–21 use ...
Get Java How To Program, Late 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.