Originally posted by Sandeep Vaid:
A. Is it true that if we don't provide our hashCode() then default Object class hashCode() will add each (our) object in a sepearte bucket. Is this true?
That is true because Object class's hashCode (and equals) is based on the memory address of the Object which is unique for every object. So no two objects (i.e. objects of classes that don't implement equals and hashCode method) can be considered equal.
Originally posted by Sandeep Vaid:
If yes, then
1. In HashSet and LinkedHashSet even duplicate(meaninfully equal) objects will be added in seperate bucket and as no two object are in the same bucket, then no two objects can be equal.
Right. Because of the above reason. Do not forget that we are talking about classes that do not implement hashCode and equals methods. If you think two objects of a class can be meaningfully equal (even though they are two different physical objects), then you ought to implement equals and hashCode in that class.
Most of the times, objects such as Strings and Integers are used as keys in Maps. They implement (override) hashCode and equals methods properly. So it is never a problem to use them in Maps.