代码:
Collections.sort(mylist, new Comparator<String>(){
public int compare(String a, String b){
return a.compareToIgnoreCase(b);
}
});
第一个参数是一个list<String>, 问一下我查看api发现Comparator接口有两个方法,一个compare,一个equals,为什么这里只实现了一个compare就当做参数传给sort了,equals不用实现吗? 谢谢 。
解决方案 »
- java中如何查询,修改,删除文件指定中的数据啊??不用数据库!!
- 关于APPLET的问题。急
- JAVA 建立数据库的问题(救命啊!)
- 跪求一个用j2me编写手机幻灯片(要代码)
- 形如\u00a5的unicode 无法正常显示
- 哪位大侠帮忙写个点对点的聊天工具呀.有基本功能就行了..来帮忙救火呀.分不够再添
- jTabbedPane里面怎么可以把一个图形加进去。
- 求救:谁有从服务器下载文件(一次下载一个文件就可以)的class 文件或着着方面的信息吗?90分必送
- 急急急!!!用到parseInt函数应该import java.lang.*;是吗?为何有错呢?
- 请问各位大神,这种java应用程序是用什么开发出来的?难度大吗?
- Set接口问题
- 新手 几道编程题
== 0) == (x.equals(y)). Generally speaking, any class that implements the
Comparable interface and violates this condition should clearly indicate this
fact. The recommended language is “Note: This class has a natural ordering
that is inconsistent with equals.”The final paragraph of the compareTo contract, which is a strong suggestion
rather than a true provision, simply states that the equality test imposed by the
compareTo method should generally return the same results as the equals
method. If this provision is obeyed, the ordering imposed by the compareTo
method is said to be consistent with equals. If it’s violated, the ordering is said to
be inconsistent with equals. A class whose compareTo method imposes an order
that is inconsistent with equals will still work, but sorted collections containing
elements of the class may not obey the general contract of the appropriate collection
interfaces (Collection, Set, or Map). This is because the general contracts
for these interfaces are defined in terms of the equals method, but sorted collections
use the equality test imposed by compareTo in place of equals. It is not a
catastrophe if this happens, but it’s something to be aware of.