You are supposed to return the same value when you consider the two objects "the same." By always returning 0 you indicate that every object of that class is "the same as" every other object.
It is not OK to make these kinds of assumptions. Rather, all you should say is "Objects of this class need to be held in collections, and compared for equality, and therefore I need to override BOTH hashCode() and equals()," OR, "Objects of this class need to be sorted, and therefore I need to implement Comparable."
A collection that contains no duplicate elements. More formally, sets contain no pair of elements e1 and e2 such that e1.equals(e2), and at most one null element
Both the string will have same hashcode and therefore if we try to add them in HashSet then only 's' can be added, as 's1' will be considered as duplicate on the basis of hashcode. Am I right?
If the compareTo method returns 0 or true, the element is considered to be in the list and so discarded as duplicate element. Am I right?