• ... into its separate words. Method flatMap receives a Function that maps an object into a stream of elements. In this case, the object is a String containing words and the result is a Stream<String> for the individual words. The lambda in line 19 passes the String representing a line of text to Pattern method splitAsStream (added in Java SE 8), which uses the regular expression specified in the Pattern (line 14) to tokenize the String into its individual words. The result of line 19 is a Stream<String> for the individual words in all the lines of text. (This lambda could be replaced with the method reference pattern::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.