This week's book giveaway is in the Android forum.
We're giving away four copies of Learning Java by Building Android Games and have Jean-Marcel Belmont on-line!
See this thread for details.
Win a copy of Learning Java by Building Android Games this week in the Android forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • Devaka Cooray
Saloon Keepers:
  • Ganesh Patekar
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
Bartenders:
  • Ron McLeod
  • Frits Walraven
  • Pete Letkeman

Sybex OCP Java 8 Study Guide: p220 query (possible erratum?)  RSS feed

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne Boyarsky & Scott Selikoff

A small query about the second statement in the final paragraph of p220:

“The groupingBy() collector tells collect() that it should group all of the elements of the stream into lists, organizing them by the function provided. This makes the keys in the map the function value and the values the function results.”

Would it not be more a case of:
This makes the keys in the map the function results (returns from Function’s apply(...) method), while the values are lists of function argument giving the same result.

My wording is not great due to the complexity of this situation – there’s probably a better way to express it, or maybe I’ve misunderstood the intention of the original statement, or how the code works!

EB
 
Marshal
Posts: 60759
189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, let's have a look at the Collectors#groupingBy() method.
It tells you that the “K”s are the results returned from the apply() method. It says the

values are Lists containing the input elements which map to the associated key under the classification function.

I see what you mean about the wording. Now let's have a look at Function. That has one abstract method, apply(), which takes any of the elements handled by the Stream and produces a “R” (probably short for Result) from it. That “R” will constitute one of the “K”s in the resultant Map; the associated “V” is a List to which the element sent to the apply() method is added. I think I would prefer your wording myself, but don&apos't call something a return from a method. You should only call something a return when it is in the form of money (or some other profit).
I would word it that the “K”s are the results from applying Function#apply() and the “V”s are Lists of the elements which produced that result from Function#apply().
 
E Byrne
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Well, let's have a look at the Collectors#groupingBy() method.
It tells you that the “K”s are the results returned from the apply() method. It says the

values are Lists containing the input elements which map to the associated key under the classification function.

I see what you mean about the wording. Now let's have a look at Function. That has one abstract method, apply(), which takes any of the elements handled by the Stream and produces a “R” (probably short for Result) from it. That “R” will constitute one of the “K”s in the resultant Map; the associated “V” is a List to which the element sent to the apply() method is added. I think I would prefer your wording myself, but don&apos't call something a return from a method. You should only call something a return when it is in the form of money (or some other profit).
I would word it that the “K”s are the results from applying Function#apply() and the “V”s are Lists of the elements which produced that result from Function#apply().



Thanks, Campbell

(Re my rather sloppy use of the word “return”: I suppose I would have called it “return value” (as per the title of Table 4.11’s last column), but wanted to avoid the word “value” for fear of confusing it with the Map’s “value” parameter!)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!