亚洲高清中文字幕精品不卡,激情综合六月,国产成人aa在线观看视频,国产精品一区久久,国产女人综合久久精品视,四虎影视国产精品一区二区

當(dāng)前位置: 首頁 / 技術(shù)干貨 / 正文
好程序員Java培訓(xùn)分享HashMap成員變量解析

2020-10-22

Java培訓(xùn)

  好程序員Java培訓(xùn)分享HashMap成員變量解析,首先看一下HashMap的一些靜態(tài)常量。diyi個是DEFAULT_INITIAL_CAPACITY,默認(rèn)初始大小,16。從注釋中可以了解到,大小必須為2的指數(shù)。這里的16,采用的1左移4位實現(xiàn)。而“aka”,是asknownas的縮寫。

 /**

 * The default initial capacity - MUST be a power of two.

好程序員

 **/

static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16

 

接下來是最大容量,當(dāng)通過任何一個構(gòu)造函數(shù)的參數(shù)隱式指明時使用該值。必須是2的指數(shù),且小于等于1<<30,即230次方。

 

/**

 * The maximum capacity, used if a higher value is implicitly specified

 * by either of the constructors with arguments.

 * MUST be a power of two <= 1<<30.

 **/

static final int MAXIMUM_CAPACITY = 1 << 30;

 

接下來是負(fù)載因子,默認(rèn)值為0.75F

 

/**

 * The load factor used when none specified in constructor.

 **/

static final float DEFAULT_LOAD_FACTOR = 0.75f;

 

接下來是和紅黑樹相關(guān)的幾個常量。在jdk1.8中,如果哈希表中的鏈表太長,就會轉(zhuǎn)化為一個紅黑樹。

 

TREEIFY_THRESHOLD,表示要轉(zhuǎn)為紅黑樹的最小元素個數(shù),即8。把紅黑樹轉(zhuǎn)化為鏈表的門限個數(shù)是6.MIN_TREEIFY_CAPACITY64,表示把鏈表轉(zhuǎn)化為紅黑樹的最小元素個數(shù)。否則,如果太多節(jié)點在一個鏈表中時,哈希表會擴容,而不會轉(zhuǎn)化為紅黑樹。

 

/**

 * The bin count threshold for using a tree rather than list for a

 * bin. Bins are converted to trees when adding an element to a

 * bin with at least this many nodes. The value must be greater

 * than 2 and should be at least 8 to mesh with assumptions in

 * tree removal about conversion back to plain bins upon

 * shrinkage.

 **/

static final int TREEIFY_THRESHOLD = 8;

/**

 * The bin count threshold for untreeifying a (split) bin during a

 * resize operation. Should be less than TREEIFY_THRESHOLD, and at

 * most 6 to mesh with shrinkage detection under removal.

 **/

static final int UNTREEIFY_THRESHOLD = 6;

/**

 * The smallest table capacity for which bins may be treeified.

 * (Otherwise the table is resized if too many nodes in a bin.)

 * Should be at least 4 * TREEIFY_THRESHOLD to avoid conflicts

 * between resizing and treeification thresholds.

 **/

static final int MIN_TREEIFY_CAPACITY = 64;

 

接下來是table,它是保存HashMap的最主要的數(shù)據(jù)結(jié)構(gòu),如下圖。從注釋中也可以了解到,table的大小一定是2的指數(shù)。

 

/**

 * The table, initialized on first use, and resized as

 * necessary. When allocated, length is always a power of two.

 * (We also tolerate length zero in some operations to allow

 * bootstrapping mechanics that are currently not needed.)

 **/

transient Node<K,V>[] table;

 

接下來是entrySet,如下圖。它保存緩存的映射關(guān)系集合。注意,keySet()values()使用的是父類AbstractMap的屬性。

 

/**

 * Holds cached entrySet(). Note that AbstractMap fields are used

 * for keySet() and values().

 **/

transient Set<Map.Entry<K,V>> entrySet;

 

最后是一些其他的屬性,包括HashMap中元素個數(shù)size,修改次數(shù)modCount,下一次進行resize的門限個數(shù),以及負(fù)載因子loadFactor,如下圖。需要注意的是,loadFactorfinal的,也就是說,它一旦被賦值,就不能再修改了。

 

/**

 * The number of key-value mappings contained in this map.

 **/

transient int size;

/**

 * The number of times this HashMap has been structurally modified

 * Structural modifications are those that change the number of mappings in

 * the HashMap or otherwise modify its internal structure (e.g.,

 * rehash). This field is used to make iterators on Collection-views of

 * the HashMap fail-fast. (See ConcurrentModificationException).

 **/

transient int modCount;

/**

 * The next size value at which to resize (capacity * load factor).

 * @serial

 **/

// (The javadoc description is true upon serialization.

// Additionally, if the table array has not been allocated, this

// field holds the initial array capacity, or zero signifying

// DEFAULT_INITIAL_CAPACITY.)

int threshold;

/**

 * The load factor for the hash table.

 *

 * @serial

 **/

final float loadFactor;

  以上就是關(guān)于好程序員Java培訓(xùn)之解析HashMap成員變量的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,請關(guān)注好程序員Java培訓(xùn)官網(wǎng)、微信公眾號等平臺。

Java培訓(xùn):http://m.enghua.cn/javaEE_class.shtml

好程序員公眾號

  • · 剖析行業(yè)發(fā)展趨勢
  • · 匯聚企業(yè)項目源碼

好程序員開班動態(tài)

More+
  • HTML5大前端 <高端班>

    開班時間:2021-04-12(深圳)

    開班盛況

    開班時間:2021-05-17(北京)

    開班盛況
  • 大數(shù)據(jù)+人工智能 <高端班>

    開班時間:2021-03-22(杭州)

    開班盛況

    開班時間:2021-04-26(北京)

    開班盛況
  • JavaEE分布式開發(fā) <高端班>

    開班時間:2021-05-10(北京)

    開班盛況

    開班時間:2021-02-22(北京)

    開班盛況
  • Python人工智能+數(shù)據(jù)分析 <高端班>

    開班時間:2021-07-12(北京)

    預(yù)約報名

    開班時間:2020-09-21(上海)

    開班盛況
  • 云計算開發(fā) <高端班>

    開班時間:2021-07-12(北京)

    預(yù)約報名

    開班時間:2019-07-22(北京)

    開班盛況
IT培訓(xùn)IT培訓(xùn)
在線咨詢
IT培訓(xùn)IT培訓(xùn)
試聽
IT培訓(xùn)IT培訓(xùn)
入學(xué)教程
IT培訓(xùn)IT培訓(xùn)
立即報名
IT培訓(xùn)

Copyright 2011-2023 北京千鋒互聯(lián)科技有限公司 .All Right 京ICP備12003911號-5 京公網(wǎng)安備 11010802035720號

主站蜘蛛池模板: 国产精品久久免费视频 | 国产乱视频网站 | 最新国产精品视频 | 欧美性一交激情视频在线 | 99视频在线观看高清 | 国产精品久久久久久久久久久搜索 | 天天干夜夜做 | 亚洲乱码国产乱码精品精98 | 国产亚洲精品国产 | 丁香婷婷小说 | 国产99色| 久久国产精品免费视频 | 国产精品高清一区二区三区不卡 | 久久久久国产精品免费 | 99久久精品免费看国产交换 | 日本久久久久久 | 国产综合在线视频 | 欧美视频免费播放 | 免费人成年短视频在线观看网站 | 福利视频午夜 | 善良的嫂子3中文 | 欧美日韩中文字幕久久伊人 | 男人天堂1024| 亚洲国产成人在人网站天堂 | 99精品视频在线在线视频观看 | 嫩草影院免费在线观看 | 斗破苍穹漫画扑飞在线观看免费版 | 99国产精品视频免费观看 | 久久成人免费播放网站 | 色迷迷影院 | 精品免费国产 | 国产在线观看免费完整版中文版 | 操你.com| 久久久久国产成人精品 | 久久99精品久久 | 国产va在线播放 | 精品久久久中文字幕一区 | 国产自产v一区二区三区c | 久久福利资源国产精品999 | 泡泡影视福利影院 | 免费人成在线观看网站品爱网 |