When String hash is computed?
If I am inserting 10 million strings in a HashSet then will it compute it for each insertion or it would have already computed hash (as String is immutable object)?
Although officially it is unspecified, String has a transient field for the hash code. This field is calculated when hashCode is called and the field is 0. So unless the hash code of a String actually 0 it will be calculated only once.