[英]How to find max or min between a range on an arraylist?
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. 获得arraylist的最大值或最小值,但我正在寻找一种方法来获得一定范围之间的最大值或最小值。
For example, what is the max between index 0 and index 5? 例如,索引0和索引5之间的最大值是多少?
Use list.subList
to run the operation on a portion of the List
: 使用
list.subList
对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). list.subList(0,6)
返回索引0和5(包括)之间的原始列表部分的视图。
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));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.