Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Plain View
HDFS >> mail # user >> Re: CompareTo vs equals

Copy link to this message
Re: CompareTo vs equals
IntPair  class has these 2 methods, i understand that compareTo is used for comparing but when is equals method used and is it necessary to write it when we alread have implemented compareTo method.

public int compareTo(IntPair that) {
int cmp = first.compareTo(that.first);
cmp = second.compareTo(that.second);
return cmp;
public boolean equals(Object obj) {
if (obj instanceof IntPair){
IntPair that = (IntPair)obj;
return (first.equals(that.first) && second.equals(that.second));
return false;


Ted Yu 2013-03-28, 03:22