我在使用这段代码时遇到了麻烦.基本上,给出了主要功能,并且它被要求开发CountDown编译代码的最简单版本的类.
班级主要:
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Main {
public static void main(String[] args) {
CountDown a = new CountDown(3,15);
CountDown b = new CountDown(2,20);
CountDown c = new CountDown(3,15);
List<CountDown> lst = new ArrayList<CountDown>();
lst.add(a);
lst.add(b);
lst.add(c);
Set<CountDown> set = new HashSet<CountDown>();
set.addAll(lst);
lst.clear();
lst.addAll(set);
Collections.sort(lst);
for(E e : lst) {
System.out.println(e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
类CountDown:
public class CountDown implements Comparable<CountDown> {
private int hour;
private …Run Code Online (Sandbox Code Playgroud) 我知道有
Collections.max(list);
Collections.min(list);
Run Code Online (Sandbox Code Playgroud)
要获得arraylist的最大值或最小值,但我正在寻找一种方法来获得某个范围之间的最大值或最小值.
例如,索引0和索引5之间的最大值是多少?
java ×2