java - Hashmap hashtable size limit less than max allowed limit for array index -


i wish validate below understanding please suggest.

in java, regular array can have indices maximum value of int type 2 raised power 31 minus -1 , since hashmap maximum_capacity int too, can go value too.

but since hashmap internally needs table length(bucket size) power of two limit gets curtailed - static final int maximum_capacity = 1 << 30; since value nearest power of two 1<<31 -1 .

am correct in understanding?

all answers here mention sign bit limit not power of two requirement,

/**      * table, resized necessary. length must power of two.      */  transient entry<k,v>[] table = (entry<k,v>[]) empty_table; 

also, understand size limit array or hashmap (bucket size) has nothing system / object / heap memory limitations max_range int data type (index data type)and other logical requirements (like power of 2 etc).

you (more or less) correct in reasoning array size.

but size limit on internal array hashmap.table not limit size of hashmap (i.e. number entries can stored in hashmap).

each element in array linked list of entry objects of unlimited size, therefore there no hard limit on number of entries can stored in hashmap.


Comments