O'Reilly logo
  • Tansu Dasli thinks this is interesting:

17 Map<String, Long> wordCounts = 18 Files.lines(Paths.get("Chapter2Paragraph.txt")) 19 .flatMap(line -> pattern.splitAsStream(line)) 20 .collect(Collectors.groupingBy(String::toLowerCase, 21 TreeMap::new, Collectors.counting()));

From

Cover of Java® 9 for Programmers, Fourth Edition

Note

        /* another split way
        Files.lines(Paths.get(path + &quot;concordances.txt&quot;)).flatMap(line -&gt; Stream.of(line.split(&quot;\\W+&quot;)))
        .forEach(System.out::println);
        */