Test code:
int initialcapacity = 16;
float loadfactor = 0.75f;
hashmap<string,string> HashMap = new hashmap<> (initialcapacity,loadfactor);
System.out.println (Hashmap.put ("1", "V1"));
System.out.println (Hashmap.put ("1", "V2"));
Iterator<string> it = Hashmap.keyset (). Iterator ();
while (It.hasnext ()) {
System.out.println (Hashmap.get (It.next ()));
}
- //system default initial capacity, must be 2 of the power of N, this is due to optimization considerations
- static final int default_initial_capacity = 16;
- //system default maximum capacity
- static final int maximum_capacity = 1 << 30;
- //system default load factor, which can be specified in the constructor
- static final float default_load_factor = 0.75f;
- //table for storage, length can be adjusted, and must be 2 n power
- transient entry[] table;
- the Key-value map number of the current map, which is the current size
- transient int size;
- //Threshold value
- int threshold;
- //hash Table load factor
- final float loadfactor;
- //used to ensure that iterators are used, HashMap is not changed
- transient volatile int modcount;
HashMap two parameter initialcapacity (Initialize container size), Loadfactor (load factor) in the constructor method
Research on Java collection classes