This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Modern JavaScript for the Impatient and have Cay Horstmann on-line!
See this thread for details.
Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Doubt about Streams

 
Ranch Hand
Posts: 98
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

It probably is a silly thing, but I am not able to see here:



why c1 is an int and why c2 is a String. Anyone can give me the light?

Thanks in advance.
 
Ranch Hand
Posts: 135
5
Eclipse IDE Postgres Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You nailed it. Even I couldn't figure it out at a glance. So this is what's going on here. You probably know that we have 3 versions of `reduce()`.




And, look at the generics carefully for the below version which is the one that you have used in your code



In your case, 0 is passed as the identity. It's an Integer. Therefore, your `BiFunction` supposed to be `BiFunction<Integer, ? super String, Integer>`

Btw; it's is redundant to use both `parallelStream()` and `parallel()` both together. The end result is however a parallel stream.

The reason we gave two methods to get the same thing is, parallelStream() is defined in Collections interface. That is little bit convenient. Something like we have a forEach() defined for List interface.

 
Alfonso Sanz
Ranch Hand
Posts: 98
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a ton Mr. Jude Niroshan!!
Now is clearer, but now I am more scared about the exam if it is supposed for me to know all the signatures of all methods....
   

Again: thank you!
 
author & internet detective
Posts: 40169
812
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Alfonso Sanz wrote:Thanks a ton Mr. Jude Niroshan!!
Now is clearer, but now I am more scared about the exam if it is supposed for me to know all the signatures of all methods....
   

Again: thank you!


Not all the methods. But a good number of them. This is where a study guide helps. It shows what you do need to memorize and helps reinforce it so you do!
 
Every snowflake is perfect and unique. And every snowflake contains a very tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic