• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Liutauras Vilda
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
Bartenders:
  • Himai Minh
  • Carey Brown
  • Frits Walraven

Need help to understand a question about Streams

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the given question the line "q2" is wrong because c1 is an int and cant use length().
Can someone explain me, why c1 is an int? I thought c1 and c2 stands both for the elements in the list which are strings.

 
Saloon Keeper
Posts: 4560
182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Alexander,

welcome to the Ranch and enjoy the stay!

If you look at the API of the three-parameter version of reduce, you'll see that it starts with U identity. You start with the Int 0, so java knows the U is an Int. The second line should be a BiFunction<Integer, String, Integer> and so you are right: it should be c1 + c2.length()
 
Drove my Chevy to the levee but the levee was dry. A wrung this tiny ad and it was still dry.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic