Which of the following are true given the declaration IntStream is = IntStream.empty()
? (Choose all that apply.)
average()
returns the type int.average()
returns the type OptionalInt.findAny()
returns the type int.findAny()
returns the type OptionalInt.sum()
returns the type int.sum()
returns the type OptionalInt.D, E.
The sum()
method returns an int rather than an OptionalInt because the sum of an empty list is zero.
Therefore, option E is correct.
The findAny()
method returns an OptionalInt because there might not be any elements to find.
Therefore, option D is correct.
The average()
method returns an OptionalDouble since averages of any type can result in a fraction.
Therefore, options A and B are both incorrect.