Can Java’s hashCode produce same value for different strings?

A Java hash code is 32bits. The number of possible strings it hashes is infinite.

So yes, there will be collisions. The percentage is meaningless – there is an infinite number of items (strings) and a finite number of possible hashes.

Leave a Comment