About Question enthuware.ocpjp.ii.v11.2.1886 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
dongyingname
Posts: 18
Joined: Sat Jun 22, 2019 4:10 pm
Contact:

About Question enthuware.ocpjp.ii.v11.2.1886 :

Post by dongyingname »

Code: Select all

class Book {
   double price;
   String title;
   public double getPrice(){....}
   //constructors and setters
}
using thrid option in main with .toDouble() removed.

Code: Select all

double d = books.stream().flatMap(bs -> bs.stream()).map(book -> book.getPrice()).sum();
It doesn't compile, and the error

Code: Select all

cannot find symbol
  symbol:   method sum()
  location: interface Stream<Double>
points to .sum()
I knew that autoboxing was expensive in stream, but I need help explain why this happens.

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocpjp.ii.v11.2.1886 :

Post by admin »

Well, does Stream have sum() method?
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 32 guests