Comments for http://horstmann.com/unblog/2019-07-23/index.html?utm_source=dlvr.it
- QIn reply tosystem⬆:Yanming Zhou @quaff
Collections.filtering
should beCollectors.filtering
- CCay Horstmann @cayhorstmann
Sorry about the late reply. I fixed that too.
- LIn reply tosystem⬆:@lxsyojdzecdjuspcjh
I think there might be an error in the first downstream collector example "first name to people" example.
I think the return type is slightly wrong, and alsotoMap()
is not the right method. It probably should be:Map<String, List<Person>> firstNameToPeople = people.collect( Collectors.groupingBy(Person::getFirstName, Collectors.toList()));
Similar with the second example
Map<String, Long> firstNameCount = people.collect( Collectors.groupingBy(Person::getFirstName, Collectors.counting()));
I attempt with Java 8, 11 and 14
Gregor
- CCay Horstmann @cayhorstmann
Thanks, you are right. I meant
groupingBy
. I fixed the code. NB. In a recent blog (https://horstmann.com/unblog/2020-06-05/index.html), I wrote about actually checking every line of code in a book. I've got to extend it to my blogs.