Reputation: 125
I know there is
Collections.max(list);
Collections.min(list);
To get the max or min of an arraylist, but I am looking for a way to get the max or min between a certain range.
For example, what is the max between index 0 and index 5?
Upvotes: 2
Views: 1431
Reputation: 122026
You can go with sublist. Make a list with range and then pass it as param to the max.
For ex :
Collections.max(list.subList(0,6));
Upvotes: 7
Reputation: 394156
Use list.subList
to run the operation on a portion of the List
:
Collections.max(list.subList(0,6));
list.subList(0,6)
returns a view of the portion of the original list between indices 0 and 5 (inclusive).
Upvotes: 10