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.

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

Thanks

Sai

Reply via email to