Someone told me that compare() and compareTo() method of comparable and comparator interface in java using hashcode to compare string or object in java.
I do not found any relevant evidence for same.
So the main question is what these two method using internally to compare objects
Theoretically what I know about the hashcode is:
The hashcode of a Java Object is simply a number, it is 32-bit signed int, that allows an object to be managed by a hash-based data structure. We know that hash code is an unique id number allocated to an object by JVM. But actually speaking, Hash code is not an unique number for an object. If two objects are equals then these two objects should return same hash code. So we have to implement hashcode() method of a class in such way that if two objects are equals, ie compared by equal() method of that class, then those two objects must return same hash code. If you are overriding hashCode you need to override equals method also.