At least there should be indicated an application in which the hash code is frozen while it is in the collection of interest. As a rule, hashCode will change when creating an object (for example, adding it to ArrayList), then you add it to the collection and stop changing. Later, if you remove it from the collection, you can change it again. I would say that it is best to use immutable data structures (ala String or your own type with ending ending) with collections that rely on a hash code (for example, a HashMap or HashSet key).
source
share