hashMap有4个构造函数:

  1. public HashMap(int initialCapacity, float loadFactor)
  2. public HashMap(int initialCapacity)
  3. public HashMap()
  4. public HashMap(Map<? extends K, ? extends V> m)
/*** Constructs an empty <tt>HashMap</tt> with the specified initial* capacity and load factor.** @param  initialCapacity the initial capacity* @param  loadFactor      the load factor* @throws IllegalArgumentException if the initial capacity is negative*         or the load factor is nonpositive*/public HashMap(int initialCapacity, float loadFactor) {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 <tt>HashMap</tt> with the specified initial* capacity and the default load factor (0.75).** @param  initialCapacity the initial capacity.* @throws IllegalArgumentException if the initial capacity is negative.*/public HashMap(int initialCapacity) {this(initialCapacity, DEFAULT_LOAD_FACTOR);}/*** Constructs an empty <tt>HashMap</tt> with the default initial capacity* (16) and the default load factor (0.75).*/public HashMap() {this.loadFactor = DEFAULT_LOAD_FACTOR; // all other fields defaulted
    }/*** Constructs a new <tt>HashMap</tt> with the same mappings as the* specified <tt>Map</tt>.  The <tt>HashMap</tt> is created with* default load factor (0.75) and an initial capacity sufficient to* hold the mappings in the specified <tt>Map</tt>.** @param   m the map whose mappings are to be placed in this map* @throws  NullPointerException if the specified map is null*/public HashMap(Map<? extends K, ? extends V> m) {this.loadFactor = DEFAULT_LOAD_FACTOR;putMapEntries(m, false);}

转载于:https://www.cnblogs.com/hujinshui/p/9950077.html

HashMap构造函数有哪些相关推荐

  1. 面试官再问你 HashMap 底层原理,就把这篇文章甩给他看

    来自:烟雨星空 前言 HashMap 源码和底层原理在现在面试中是必问的.因此,我们非常有必要搞清楚它的底层实现和思想,才能在面试中对答如流,跟面试官大战三百回合.文章较长,介绍了很多原理性的问题,希 ...

  2. HashMap内部结构深入剖析

    2019独角兽企业重金招聘Python工程师标准>>> java.util.HashMap是很常见的类,前段时间公司系统由于对HashMap使用不当,导致cpu百分之百,在并发环境下 ...

  3. 集合框架—HashMap

    HashMap提供了三个构造函数: HashMap():构造一个具有默认初始容量 (16) 和默认加载因子 (0.75) 的空 HashMap. HashMap(int initialCapacity ...

  4. JDK1.8源码分析之HashMap(一) (转)

    一.前言 在分析jdk1.8后的HashMap源码时,发现网上好多分析都是基于之前的jdk,而Java8的HashMap对之前做了较大的优化,其中最重要的一个优化就是桶中的元素不再唯一按照链表组合,也 ...

  5. HashMap 怎么 hash?又如何 map?

    2019独角兽企业重金招聘Python工程师标准>>> HashMap 是 Java 中 Map 的一个实现类,它是一个双列结构(数据+链表),这样的结构使得它的查询和插入效率都很高 ...

  6. 【Java集合学习系列】HashMap实现原理及源码分析

    HashMap特性 hashMap是基于哈希表的Map接口的非同步实现,继承自AbstractMap接口,实现了Map接口(HashTable跟HashMap很像,HashTable中的方法是线程安全 ...

  7. HashMap 详解

    HashMap也是我们使用非常多的Collection,它是基于哈希表的 Map 接口的实现,以key-value的形式存在.在HashMap中,key-value总是会当做一个整体来处理,系统会根据 ...

  8. java 的HashMap底层数据结构

    HashMap也是我们使用非常多的Collection,它是基于哈希表的 Map 接口的实现,以key-value的形式存在.在HashMap中,key-value总是会当做一个整体来处理,系统会根据 ...

  9. 【集合框架】JDK1.8源码分析之HashMap(一)

    转载自  [集合框架]JDK1.8源码分析之HashMap(一) 一.前言 在分析jdk1.8后的HashMap源码时,发现网上好多分析都是基于之前的jdk,而Java8的HashMap对之前做了较大 ...

最新文章

  1. php mysql什么意思_php MySQLi是什么意思?
  2. 《演讲之禅》助你成长为一名合格程序员
  3. 使用pip安装python库的几种方式,解决pip安装python库慢的问题
  4. Numpy-浅拷贝和深拷贝
  5. d3.js(相当于svg的JQ)
  6. 【基础知识】进程通信之共享内存+信号量
  7. Fixchart图表组件——介绍
  8. shell循环和函数引用
  9. 网络空间安全现状与国家战略
  10. 软考高项10大知识领域47个过程ITTO一页纸(含记忆口诀)
  11. 电视盒子线刷固件教程B860AV2.1-A-M-T版
  12. python测验6_Python语言程序设计 - 测验6: 组合数据类型 (第6周)
  13. Seaweed-fs
  14. 网页知识入门-浏览器和网页生成
  15. ilm 和dlm差异_第八章 大数据对象设计与维护
  16. 鼠标上下滚轮不灵敏的修复方法
  17. stm32f103c8t6调试-while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET );卡死
  18. MVC5 + EF6 + Bootstrap3 (9) HtmlHelper用法大全(下)
  19. pycharm贪吃蛇
  20. cube station下载_cube station魔方软件下载

热门文章

  1. Linux 搭建golang开发环境
  2. HDU 2009 求数列的和
  3. python-logging用法
  4. worktools-源码下拉问题
  5. SQL Server 数据库状态选项
  6. Python中纠结处之其一—— 静态方法、类方法
  7. NO。58 新浪微博顶部新评论提示层效果——position:fixed
  8. 【JLOI2011】飞行路线
  9. Jmeter-接口测试相关
  10. 快速理解编码,unicode与utf-8