See this code lines:
HashMap<String, Integer> mapJdK = new HashMap<String, Integer>();
suppose the default load factor is 0.75 and the default initial capacity of a hash map is 16. This means that the threshold for the next resize equates like:
DEFAULT_INITIAL_CAPACITY = 16;
DEFAULT_LOAD_FACTOR = 0.75;
THRESHOLD = DEFAULT_INITIAL_CAPACITY * DEFAULT_LOAD_FACTOR;
The hash map will automatically rehash the contents of the hash map into a new array with a larger capacity. This happens when the number of data in the hash map exceeds the THRESHOLD. Each resize leads to a doubled capacity 16*0.75, 32*0.75, 64*0.75, etc.Like
The minimal initial capacity would be (number of data)/0.75+1 then java hashmap with reasonable values:
int capacity = (int) ((expected_maximal_number_of_data)/0.75+1);
HashMap<String, Integer> mapJdK = new HashMap<String, Integer>(capacity);