java hashmap 构造函数_HashMap构造函数有哪些

/*** 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);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值