Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

OCP 17 Study Guide Chapter 10 Exam Essentials

 
Greenhorn
Posts: 25
3
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Everyone

The textbook says:

Compare groupingBy() and partitioningBy(). The groupingBy() method is a terminal operation that creates a Map. The keys and return types are determined by the parameters you pass. The values in the Map are a Collection for all the entries that map to that key. The partitioningBy() method also returns a Map. This time, the keys are true and false. The values are again a Collection of matches. If there are no matches for that boolean, the Collection is empty.



I actually found this paragraph very misleading, at the point that I had to go back and review the topic, after many hours spent trying to get and memorize comparators.
For what I finally got, groupingBy() and partitioningBy() methods are not terminal operations and they don't return Map. They aren't Stream's methods, but they are static methods in class Collectors, that returns collector objects. The terminal operation in this case is collect().
 
Master Rancher
Posts: 4981
79
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup, that's exactly right.  Typically, people create the groupingBy() collector in the same line as the collect() method call, so it's tempting to think of them as all happening together in the same step.  But when you look more closely, you're quite correct that the groupingBy is not terminal, and not even a stream operation... but the collect() is what actually terminates the stream.
 
author & internet detective
Posts: 41967
911
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've added this to errata and credited you. Thanks for noticing!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic