/*** Constructs an empty HashMap with the specified initial
* capacity and load factor.
*
*@paraminitialCapacity the initial capacity
*@paramloadFactor the load factor
*@throwsIllegalArgumentException if the initial capacity is negative
* or the load factor is nonpositive*/
public HashMap(int initialCapacity, floatloadFactor) {if (initialCapacity < 0)throw new IllegalArgumentException("Illegal initial capacity: " +initialCapacity);if (initialCapacity >MAXIMUM_CAPACITY)
initialCapacity=MAXIMUM_CAPACITY;if (loadFactor <= 0 ||Float.isNaN(loadFactor))throw new IllegalArgumentException("Illegal load factor: " +loadFactor);this.loadFactor =loadFactor;this.threshold =tableSizeFor(initialCapacity);
}/*** Constructs an empty HashMap with the specified initial
* capacity and the default load factor (0.75).
*
*@paraminitialCapacity the initial capacity.
*@throwsIllegalArgumentException if the initial capacity is negative.*/
public HashMap(intinitialCapacity) {this(initialCapacity, DEFAULT_LOAD_FACTOR);
}/*** Constructs an empty HashMap with the default initial capacity
* (16) and the default load factor (0.75).*/
publicHashMap() {this.loadFactor = DEFAULT_LOAD_FACTOR; //all other fields defaulted
}/*** Constructs a new HashMap with the same mappings as the
* specified Map. The HashMap is created with
* default load factor (0.75) and an initial capacity sufficient to
* hold the mappings in the specified Map.
*
*@paramm the map whose mappings are to be placed in this map
*@throwsNullPointerException if the specified map is null*/
public HashMap(Map extends K, ? extends V>m) {this.loadFactor =DEFAULT_LOAD_FACTOR;
putMapEntries(m,false);
}