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);
}

HashMap构造函数有哪些的更多相关文章

  1. HashMap 构造函数

    HashMap总共提供了三个构造函数 /** * Constructs an empty <tt>HashMap</tt> with the default initial c ...

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

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

  3. 图解集合4:HashMap

    初识HashMap 之前的List,讲了ArrayList.LinkedList,最后讲到了CopyOnWriteArrayList,就前两者而言,反映的是两种思想: (1)ArrayList以数组形 ...

  4. java提高篇(二三)-----HashMap

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

  5. java集合-HashMap

    HashMap基于哈希表的 Map 接口的实现,以 key-value 的形式存在.在 HashMap 中,key-value 总是会当做一个整体来处理,系统会根据 hash 算法来来计算 key-v ...

  6. Java HashMap、LinkedHashMap

    如果需要使用的Map中的key无序,选择HashMap:如果要求key有序,则选择TreeMap. 但是选择TreeMap就会有性能问题,因为TreeMap的get操作的时间复杂度是O(log(n)) ...

  7. java提高篇---HashMap

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

  8. 浅析Java中HashMap的实现

    概述 HashMap是一个散列表,是基于拉链法实现的.这个类继承了Map接口,Map接口提供了所有的哈希操作,比如set().put().remove()等,并且允许操作的键值对为null.HashM ...

  9. 【转】java提高篇(二三)-----HashMap

    原文网址: http://www.cnblogs.com/chenssy/p/3521565.html HashMap也是我们使用非常多的Collection,它是基于哈希表的 Map 接口的实现,以 ...

随机推荐

  1. 什么是Java Marker Interface(标记接口)

    先看看什么是标记接口?标记接口有时也叫标签接口(Tag interface),即接口不包含任何方法.在Java里很容易找到标记接口的例子,比如JDK里的Serializable接口就是一个标记接口. ...

  2. WPF中的TextBlock处理长字符串

    Xaml: <StackPanel> <TextBlock Margin="10" Foreground="Red"> This is ...

  3. WPF中Canvas使用

    首先知道Canvas有Left.Right.Top和Bottom这四个属性,放入Canvas的元素通过这四个属性来决定它们在Canvas里面的位置. 比如: Xaml: <Canvas Hori ...

  4. 背包问题2 (lintcode)

    这里: for(int j = 1;j <= m;j++) result[0][j] = 0x80000000; 不能从0开始,result[0][0]是可以取到的,是0.其他情况取不到才用最小 ...

  5. 数据库_5_MySQL数据库介绍

    一.MySQL数据库 MySQL:MySQL是一个关系型数据库管理系统,由瑞典MySQL AB 公司开发,目前属于 Oracle 旗下产品.MySQL 是最流行的关系型数据库管理系统之一,在 WEB ...

  6. Salt Master报错:Minion did not return. [No response]

    在salt master端执行salt ‘*’ test.ping时,某一节点出现如下报错:Minion did not return. [No response] 登陆到这一节点查看minion的日 ...

  7. intellij IDEA版本控制设置

    我们开发肯定是有版本控制的,大家以前Eclipse的时候在本地文件和版本库不一致的时候,那么文件以及所在的文件夹都会出现一个〉表示,大家能很轻松的看到本地文件修改了哪一些,但是IntelliJ中默认是 ...

  8. 设置section的距离

    在ios7中使用group类型的tableview时,第一个section距离navigationbar的距离很大,不符合这边的设计图.使用 myTableView . sectionHeaderHe ...

  9. cocos2d popSceneWithTransition()方法

    要在CCDirector.h中增加如下方法: template <typename T> void popSceneWithTransition(float t) { CCASSERT(_ ...

  10. Sass 构建之 7-1模式

    Sass 项目结构之7-1模式 7-1模式的结构:7个文件夹,1个文件. 基本上,你需要将所有的部件放进7个不同的文件夹和一个位于根目录的文件(通常用main.scss或者app.scss) 编译时会 ...