You are not getting 100 with hm.size() but 0. You don't get what you have build with that constructor. You have set the "initialCapacitiy" with that constructor :
HashMap(int initialCapacity)
Constructs an empty HashMap with the specified initial capacity and the default load factor (0.75).
But HashMap.size() return the actual number of key-value element.
Returns the number of key-value mappings in this map.
For your information :
An instance of HashMap has two parameters that affect its performance: initial capacity and load factor. The capacity is the number of buckets in the hash table, and the initial capacity is simply the capacity at the time the hash table is created. The load factor is a measure of how full the hash table is allowed to get before its capacity is automatically increased. When the number of entries in the hash table exceeds the product of the load factor and the current capacity, the hash table is rehashed (that is, internal data structures are rebuilt) so that the hash table has approximately twice the number of buckets.
Instead, simply set 100 in the loop to instanciate your List.
Map<Integer,List<Human>> hm = new HashMap<>();
for(int j=0; j < 100; j++){
hm.put(j,new ArrayList<>());
}
Or even better, use a constant somewhere like
final static int NB_LIST = 100;
Map<Integer,List<Human>> hm = new HashMap<>();
for(int j=0; j < NB_LIST; j++){
hm.put(j,new ArrayList<>());
}
hm.size()is not returning100but0.100is the initialCapacitiy not the current size. SeeHashMapandHashMap.size().