Page 1 of 1

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

Posted: Sat Sep 14, 2019 2:04 pm
by sir_Anduin@yahoo.de
is there any pattern for count, size, length and their return type?
maybe all new api return long from count?

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

Posted: Sun Sep 15, 2019 8:29 am
by admin
Generally, size and length are int and count and sum are in long. But you should not rely on it because there is no documented rule. You might see a method that doesn't follow it.

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

Posted: Fri Sep 20, 2019 5:02 pm
by codeappman@gmail.com
count is always long/Long.

In IntStream, LongStream, DoubleStream
long count()

In Collectors
Long counting()

size() in List is 'int', length in array and string is also 'int'. However, these two are too fundamental, I think it's unlikely to trick you with them in OCPJP.

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

Posted: Mon Jan 27, 2020 10:47 am
by kevvvvyp
admin wrote:
Sun Sep 15, 2019 8:29 am
Generally, size and length are int and count and sum are in long. But you should not rely on it because there is no documented rule. You might see a method that doesn't follow it.
With regards to sum:
- IntStream sum() returns int
- DoubleStream sum() returns double
- LongStream sum() returns long