WordCount { public static Map<String, Long> countWords(Stream<String> names) { return names.collect(groupingBy(name -> name, counting())); }  static Map<String, Long> countWords(Stream<String> names);  }
@Test public void passesBookExample() { Stream<String> names = Stream.of("John", "Paul", "George", "John", "Paul", "John"); Map<String, Long> counts = WordCount.countWords(names); assertEquals(3, counts.size()); assertEquals(Long.valueOf(3), counts.get("John")); assertEquals(Long.valueOf(2), counts.get("Paul")); assertEquals(Long.valueOf(1), counts.get("George")); }