[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/vvactor/Java-Guide/master/docs/java/collection/HashMap.md [Back]  [Original]


- [HashMap ](#hashmap-)
- [](#)
  - [JDK1.8](#jdk18)
  - [JDK1.8](#jdk18)
- [HashMap](#hashmap)
  - [](#)
  - [put](#put)
  - [get](#get)
  - [resize](#resize)
- [HashMap](#hashmap)


>  [changfubai](https://github.com/changfubai) 

## HashMap 
HashMap MapJava 

JDK1.8  HashMap  +  HashMap .JDK1.8  8 64 `treeifyBin`

## 
### JDK1.8
JDK1.8  HashMap  ****  ******HashMap  key  hashCode  hash   `(n - 1) & hash`  n  hash  key **

** HashMap  hash  hash  hashCode()  **

**JDK 1.8 HashMap  hash :**

JDK 1.8  hash  JDK 1.7 hash 

  ```java
      static final int hash(Object key) {
        int h;
        // key.hashCode()hashcode
        // ^ 
        // >>>:0
        return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
    }
  ```
 JDK1.7 HashMap  hash .

```java
static int hash(int h) {
    // This function ensures that hashCodes that differ only by
    // constant multiples at each bit position have a bounded
    // number of collisions (approximately 8 at default load factor).

    h ^= (h >>> 20) ^ (h >>> 12);
    return h ^ (h >>> 7) ^ (h >>> 4);
}
```

 JDK1.8  hash  JDK 1.7  hash  4 

 **** 

![jdk1.8](https://my-blog-to-use.oss-cn-beijing.aliyuncs.com/2019-7/jdk1.8.png)

### JDK1.8
jdk1.88

![JDK1.8HashMap](http://my-blog-to-use.oss-cn-beijing.aliyuncs.com/18-8-22/67233764.jpg)

****
```java
public class HashMap extends AbstractMap implements Map, Cloneable, Serializable {
    // 
    private static final long serialVersionUID = 362498820763181265L;    
    // 16
    static final int DEFAULT_INITIAL_CAPACITY = 1 

Web Proxy Viewer  |  New URL  |  Original Page