17.7 Creating a Stream<String> from a File

Figure 17.17 uses lambdas and streams to summarize the number of occurrences of each word in a file then display a summary of the words in alphabetical order grouped by starting letter. This is commonly called a concordance (http://en.wikipedia.org/wiki/Concordance_(publishing)). Concordances are often used to analyze published works. For example, concordances of William Shakespeare’s and Christopher Marlowe’s works have been used to question whether they are the same person. Figure 17.18 shows the program’s output. Line 16 of Fig. 17.17 creates a regular expression Pattern that we’ll use to split lines of text into their individual words. This Pattern represents one or more consecutive white-space ...

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.