HashMap构造函数有哪些
hashMap有4个构造函数:
public HashMap(int initialCapacity, float loadFactor)
public HashMap(int initialCapacity)
public HashMap()
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构造函数有哪些相关推荐
- 面试官再问你 HashMap 底层原理,就把这篇文章甩给他看
来自:烟雨星空 前言 HashMap 源码和底层原理在现在面试中是必问的.因此,我们非常有必要搞清楚它的底层实现和思想,才能在面试中对答如流,跟面试官大战三百回合.文章较长,介绍了很多原理性的问题,希 ...
- HashMap内部结构深入剖析
2019独角兽企业重金招聘Python工程师标准>>> java.util.HashMap是很常见的类,前段时间公司系统由于对HashMap使用不当,导致cpu百分之百,在并发环境下 ...
- 集合框架—HashMap
HashMap提供了三个构造函数: HashMap():构造一个具有默认初始容量 (16) 和默认加载因子 (0.75) 的空 HashMap. HashMap(int initialCapacity ...
- JDK1.8源码分析之HashMap(一) (转)
一.前言 在分析jdk1.8后的HashMap源码时,发现网上好多分析都是基于之前的jdk,而Java8的HashMap对之前做了较大的优化,其中最重要的一个优化就是桶中的元素不再唯一按照链表组合,也 ...
- HashMap 怎么 hash?又如何 map?
2019独角兽企业重金招聘Python工程师标准>>> HashMap 是 Java 中 Map 的一个实现类,它是一个双列结构(数据+链表),这样的结构使得它的查询和插入效率都很高 ...
- 【Java集合学习系列】HashMap实现原理及源码分析
HashMap特性 hashMap是基于哈希表的Map接口的非同步实现,继承自AbstractMap接口,实现了Map接口(HashTable跟HashMap很像,HashTable中的方法是线程安全 ...
- HashMap 详解
HashMap也是我们使用非常多的Collection,它是基于哈希表的 Map 接口的实现,以key-value的形式存在.在HashMap中,key-value总是会当做一个整体来处理,系统会根据 ...
- java 的HashMap底层数据结构
HashMap也是我们使用非常多的Collection,它是基于哈希表的 Map 接口的实现,以key-value的形式存在.在HashMap中,key-value总是会当做一个整体来处理,系统会根据 ...
- 【集合框架】JDK1.8源码分析之HashMap(一)
转载自 [集合框架]JDK1.8源码分析之HashMap(一) 一.前言 在分析jdk1.8后的HashMap源码时,发现网上好多分析都是基于之前的jdk,而Java8的HashMap对之前做了较大 ...
最新文章
- php mysql什么意思_php MySQLi是什么意思?
- 《演讲之禅》助你成长为一名合格程序员
- 使用pip安装python库的几种方式,解决pip安装python库慢的问题
- Numpy-浅拷贝和深拷贝
- d3.js(相当于svg的JQ)
- 【基础知识】进程通信之共享内存+信号量
- Fixchart图表组件——介绍
- shell循环和函数引用
- 网络空间安全现状与国家战略
- 软考高项10大知识领域47个过程ITTO一页纸(含记忆口诀)
- 电视盒子线刷固件教程B860AV2.1-A-M-T版
- python测验6_Python语言程序设计 - 测验6: 组合数据类型 (第6周)
- Seaweed-fs
- 网页知识入门-浏览器和网页生成
- ilm 和dlm差异_第八章 大数据对象设计与维护
- 鼠标上下滚轮不灵敏的修复方法
- stm32f103c8t6调试-while(ADC_GetFlagStatus(ADC1, ADC_FLAG_EOC) == RESET );卡死
- MVC5 + EF6 + Bootstrap3 (9) HtmlHelper用法大全(下)
- pycharm贪吃蛇
- cube station下载_cube station魔方软件下载