public LinkedHashMap(int initialCapacity,
float loadFactor,
boolean accessOrder)Constructs an empty LinkedHashMap instance with the specified initial capacity, load factor and ordering mode.
Parameters:
initialCapacity - the initial capacity
loadFactor - the load factor
accessOrder - the ordering mode - true for access-order, false for insertion-order
Throws:
IllegalArgumentException - if the initial capacity is negative or the load factor is nonpositive
这是API上的信息,看了之后,感觉还不是很懂,大侠们能帮忙讲解下三个参数的作用么?尤其是最后两个。谢谢
float loadFactor,
boolean accessOrder)Constructs an empty LinkedHashMap instance with the specified initial capacity, load factor and ordering mode.
Parameters:
initialCapacity - the initial capacity
loadFactor - the load factor
accessOrder - the ordering mode - true for access-order, false for insertion-order
Throws:
IllegalArgumentException - if the initial capacity is negative or the load factor is nonpositive
这是API上的信息,看了之后,感觉还不是很懂,大侠们能帮忙讲解下三个参数的作用么?尤其是最后两个。谢谢
loadFactor: 当已经被使用的Hash桶数目达到总数*loadFactor,需要进行扩容,容量变成之前的2倍
accessOrder:LRU在这里体现,当这个值为true的时候,使用的就是LRU算法,也就是最近访问的放在最前面,最近少访问的放在后面。具体实现办法是,当使用get()方法获取一个值后,会把这个值所在的hash桶放在所有桶的最前面,这样下次访问可以最快取得。说点题外话,其实,除非做那种对效率要求非常高的应用,不然真的不用关心这些数据结构的底层细节。