www.久久精品_91高清视频在线_91lu在线观看_91av视频在线_91精品久久久久久久久_久久久久国产精品www

当前位置: 首页 / 技术干货 / 正文
好程序员Java培训分享HashMap成员变量解析

2020-10-22

Java培训

  好程序员Java培训分享HashMap成员变量解析,,首先看一下HashMap的一些静态常量。diyi个是DEFAULT_INITIAL_CAPACITY,默认初始大小,16。从注释中可以了解到,大小必须为2的指数。这里的16,采用的1左移4位实现。而“aka”,是asknownas的缩写。

 /**

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

好程序员

 **/

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

 

接下来是最大容量,当通过任何一个构造函数的参数隐式指明时使用该值。必须是2的指数,且小于等于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;

 

接下来是负载因子,默认值为0.75F。

 

/**

 * The load factor used when none specified in constructor.

 **/

static final float DEFAULT_LOAD_FACTOR = 0.75f;

 

接下来是和红黑树相关的几个常量。在jdk1.8中,如果哈希表中的链表太长,就会转化为一个红黑树。

 

TREEIFY_THRESHOLD,表示要转为红黑树的最小元素个数,即8。把红黑树转化为链表的门限个数是6.MIN_TREEIFY_CAPACITY64,表示把链表转化为红黑树的最小元素个数。否则,如果太多节点在一个链表中时,哈希表会扩容,而不会转化为红黑树。

 

/**

 * 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的最主要的数据结构,如下图。从注释中也可以了解到,table的大小一定是2的指数。

 

/**

 * 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,如下图。它保存缓存的映射关系集合。注意,keySet()values()使用的是父类AbstractMap的属性。

 

/**

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

 * for keySet() and values().

 **/

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

 

最后是一些其他的属性,包括HashMap中元素个数size,修改次数modCount,下一次进行resize的门限个数,以及负载因子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;

  以上就是关于好程序员Java培训之解析HashMap成员变量的全部内容了,希望本文的内容对大家的学习或者工作具有一定的参考学习价值,请关注好程序员Java培训官网、微信公众号等平台。

Java培训:http://www.zhengmaimai.cn/javaEE_class.shtml

好程序员公众号

  • · 剖析行业发展趋势
  • · 汇聚企业项目源码

好程序员开班动态

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

    开班时间:2021-04-12(深圳)

    开班盛况

    开班时间:2021-05-17(北京)

    开班盛况
  • 大数据+人工智能 <高端班>

    开班时间:2021-03-22(杭州)

    开班盛况

    开班时间:2021-04-26(北京)

    开班盛况
  • JavaEE分布式开发 <高端班>

    开班时间:2021-05-10(北京)

    开班盛况

    开班时间:2021-02-22(北京)

    开班盛况
  • Python人工智能+数据分析 <高端班>

    开班时间:2021-07-12(北京)

    预约报名

    开班时间:2020-09-21(上海)

    开班盛况
  • 云计算开发 <高端班>

    开班时间:2021-07-12(北京)

    预约报名

    开班时间:2019-07-22(北京)

    开班盛况
IT培训IT培训
在线咨询
IT培训IT培训
试听
IT培训IT培训
入学教程
IT培训IT培训
立即报名
IT培训

Copyright 2011-2023 北京千锋互联科技有限公司 .All Right 京ICP备12003911号-5 京公网安备 11010802035720号

主站蜘蛛池模板: 成人国产一区二区三区精品 | 成人午夜精品久久不卡 | 人人澡人人射 | 久久久精品人妻一区二区三区 | 亚洲最大综合网 | 亚洲av无码一区二区三区人妖 | 四虎网站在线观看 | 99国产精品一区二区 | 久久激情五月丁香伊人 | 热99精品在线 | 美女脱了内裤张开腿让男人添 | 亚洲综合国产一区二区三区 | 亚洲影院在线播放 | 人人香蕉 | 国产96在线 | 亚洲 | 成人国产视频在线观看 | 亚洲国产国产综合一区首页 | 永久免费的av片在线电影网 | 亚州免费一级毛片 | 国产精品超清白人精品av | 国产精品密蕾丝视频 | 今野由爱毛片在线播放 | 91视频免费观看高清观看完整 | 国产一极内射視颍一 | 男女后进式猛烈xx00动态图片 | 亚洲精品久久一区二区无卡 | 特黄一级真人毛片 | 中文字幕日韩精品无码内射 | 男女一边摸一边做爽爽 | 国产精品亚洲欧美大片在线看 | 美日韩精品 | 国产一区日韩二区欧美三 | 伊人国产在线播放 | a级片网站 | 久久久久国产精品熟女影院 | 日本人强jizz多人高清 | 欧美色综合图片区19p | 久久久久这里只有精品 | 欧美日韩一区二区视频图片 | 久亚洲精品不子伦一区 | 国产欧美在线一区二区三区 |