Hash code 2026-10-31
A bounded value used to organize entries in a hash table. An equality-based collection requires equal keys to have equal hash codes, while unequal keys may collide. A Java hashCode() override must therefore use information invariant under the chosen value equality. Hashing internal subdivisions is invalid when those subdivisions are deliberately ignored by equality.[ref]
For primitive values, Java == compares values, subject to the primitive type's rules. For references, == compares object identity: it asks whether the references designate the same software object, or are both null. The equals(Object) object method permits a software class to define value equality. Its inherited Object implementation still uses object identity, so meaningful content comparison requires an appropriate override.[ref]
For example:
String a = new String("wall");
String b = new String("wall");
boolean sameObject = (a == b);  // false
boolean sameText = a.equals(b); // true
The two allocations have different object identities but equal text. Using separately allocated String data type values avoids relying on literal interning. A null receiver cannot receive an equals call; java.util.Objects.equals(a,b) is a null-safe comparison. An equals implementation should define an equivalence relation and equal software objects must have equal hashCode() results.[ref] The distinction is