Section 17.7 Creating a Stream<String> from a File

Files method lines creates a Stream<String> for reading the lines of text from a file.

Stream method flatMap (p. 760) receives a Function that maps an object into a stream—e.g., a line of text into words.

Pattern method splitAsStream (p. 760) uses a regular expression to tokenize a String.

Collectors method groupingBy with three arguments receives a classifier, a Map factory and a downstream Collector. The classifier is a Function that returns objects which are used as keys in the resulting Map. The Map factory is an object that implements interface Supplier and returns a new Map collection. The downstream Collector determines how to collect each group’s elements.

Map method entrySet ...

Get Java™ How To Program (Early Objects), Tenth 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.