Why does string rewrite hashcode in java

The hashcode of

Object is calculated based on the address, and the hashcode of String is calculated based on the internal char [].
mainly wants to ask why this method is overridden, and in which scenarios problems will occur if it is not rewritten

Mar.06,2021

basically all classes that might be used as keys for map should override hashcodewords! You should be surprised if you come across such a class without overriding equals and hashcode,.

Menu