HashMap
holds the values in an array, which can hold up to Integer.MAX_VALUE
. But this does not count collisions. Each Entry
has a next
field, which is also an entry. This is how collisions (two or more objects with the same hashcode) are resolved. So I wouldn't say there is any limit (apart from the available memory)
Note that if you exceed Integer.MAX_VALUE
, you'll get unexpected behaviour from some methods, like size()
, but get()
and put()
will still work. And they will work, because the hashCode()
of any object will return an int
, hence by definition each object will fit in the map. And then each object will collide with an existing one.