|
![]() |
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
There are three kinds of actuaries: those who can count, and those who can't.
salvin francis wrote:
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
There are three kinds of actuaries: those who can count, and those who can't.
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Stephan van Hulst wrote:Welcome to CodeRanch Alex!
You can probably simplify your collection step with a groupingBy(), rather than a toMap().
Jeanne Boyarsky wrote:* This needs to be readable for my teammates who are less comfortable with advanced streams.
There are three kinds of actuaries: those who can count, and those who can't.
Junilu Lacar wrote: for (String key : m.keySet())
result.merge(key, m.get(key), (t, u) -> {[/code]
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:
Junilu Lacar wrote: for (String key : m.keySet())
result.merge(key, m.get(key), (t, u) -> {[/code]
Whenever I see someone looping over the key set and then using get, I am forced to tell them to use entrySet instead...
Alex Shitov wrote:
Stephan van Hulst wrote:Welcome to CodeRanch Alex!
You can probably simplify your collection step with a groupingBy(), rather than a toMap().
Won't be work unfortunately, because there is no appropriate mapper for groupingBy function to flat grouped lists to one.
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:@Jeanne
Jeanne Boyarsky wrote:* This needs to be readable for my teammates who are less comfortable with advanced streams.
Can you tell me in how far the java 8(+) streams and lambdas are used in practice, compared to the java < 8 ways?
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Piet Souris wrote:Hmmm, I start to belive that Alex Shitov is right, after all. My above code does not work; I added a third Map, and the reducing reduced the complete value Collection of all Maps, no matter what key it was.
Does anyone know what I am doing wrong?
Output:
******** The combined listt of the entries************
a=[1, 2, 3]
a=[2, 3, 4]
b=[10]
a=[3, 4, 5]
******************************************************
****** the final map, incorrect ************
a=[1, 2, 3, 2, 3, 4, 10, 3, 4, 5]
b=[1, 2, 3, 2, 3, 4, 10, 3, 4, 5]
Junilu Lacar wrote:Seeing all these variations is great from a learning standpoint but I can see why Jeanne is deciding to stick with her two-loop (and probably) more imperative version.
[OCP 21 book] | [OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime. |