我有一个问题出现在过去的论文中(我正在为考试进行修订),我遇到了这个自然顺序一词,它似乎是一个关键字,因为它在纸张上以粗体显示.我已经在网上查看了Natural Order,但是找不到像我的问题要求的任何与arraylist相关的东西.
请注意,我不需要帮助解决实际问题,我只想了解自然顺序的含义.
题:
Write a Java static method called atLeast which takes an ArrayList of objects which
have natural order, an object of the element type of the ArrayList, and an integer n. A
call to the method should return true if at least n elements of the ArrayList are greater
than the element type object according to natural order, otherwise it should return false.
解决方法:
这可能意味着列表中的对象实现了Comparable:
This interface imposes a total ordering on the objects of each class that implements it. This ordering is referred to as the class’s natural ordering, and the class’s compareTo method is referred to as its natural comparison method.
该声明将如下所示:
static >
boolean atLeast(List list, T key, int n) {
...
}
标签:arraylist,java
来源: https://codeday.me/bug/20191028/1952013.html