码迷,mamicode.com
首页 > 其他好文 > 详细

Comparable Comparator equals

时间:2015-02-03 19:26:02      阅读:143      评论:0      收藏:0      [点我收藏+]

标签:

为了让类的对象间可以排序,通常有两种方法——Comparable<T> 与 Comparator<T>。

Comparable泛型接口

int java.lang.Comparable.compareTo(T o)
本对象与参数进行对比。返回为负表示小于,零表示相等,正数表示大于。
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object. 

Comparator泛型接口

int StudentComparator.compare(Student o1, Student o2)
返回值约定同Comparable泛型接口。
当一个类没有实现Comparable接口而又希望对它排序时,可以用Comparator。

equals重写

boolean Student.equals(Object o)
重写此方法达到想要的目的。

Comparable Comparator equals

标签:

原文地址:http://blog.csdn.net/chuchus/article/details/43453377

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!