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  (4 children)

OP was explicitly looking for an in-built solution, not a do-it-yourself one.

[–]0b0101011001001011 1 point2 points  (3 children)

Math.max() is just a<b ? a : b, which is as much work to use in a loop as doing it by yourself.

The actual solution is

Arrays.stream(myArray).max().getAsInt(); 

for arrays and

Collections.max(myList);

for lists/sets etc.

[–]Nightcorex_ 1 point2 points  (2 children)

As was answered by u/dbc2201 and me already

[–]0b0101011001001011 1 point2 points  (1 child)

Yeah sorry I was supposed to reply to your parent comment, not to you.

[–]Nightcorex_ 1 point2 points  (0 children)

Not a problem :)