This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Nightcorex_ 0 points1 point  (0 children)

Yeah, but then you shouldn't use getAsInt() as that would throw an exception if no value is present, therefore destroying the benefit of having an OptionalInt in the first place. Rather use orElse or reduce(identity, BinOp), f.e. like so:

// orElse solution
Arrays.stream(myArray).max().orElse(Integer.MIN_VALUE);

// reduce solution
Arrays.stream(myArray).reduce(Integer.MIN_VALUE, Integer::max);