Ben Poland wrote:Hey there,
Thanks for the reply.
Ok, I understand what you mean, I think... ? So what part of that code is actually telling "Array.sort" to find and print the highest value in the array? lol Sorry
Ben
Yes. That is the default behaviour for a String with no elements.Ben Poland wrote: . . .Output 1 simply because there are no values in the array?
No. That is because I called the orElse() method and told it to use that minimum value if there is no value already supplied. Look at the link, which I hope will make things clear.Output 2 because the Integer.MIN_VALUE is -2147483648? So that then becomes the maximum number as there are no other values. . . .
I hereby challenge you to find the maximum value in that array the way we had to do it with Java7 before the streams API was introduced.Woohoo!
Paul Clapham wrote:Does your expression now look like this?
Ben Poland wrote:If I'm understanding this correctly, the .orElse applies if there is a possible other value which in this case there obviously isn't.
Ben Poland wrote:Oops, sorry Paul, my bad I wasn't understanding what you meant so was just adding the .orElse at the end on it's own and not at the end of each line. Just got what you mean, tried it and it works fine Also I understand properly what the .orElse method is doing now.
That's how it is now and it's all good.
Thanks for the help.
Ben
P.S. Fancy throwing a challenge at me? Seems a good way to learn things...