Java HashMap Create newHashMap()

Here you can find the source of newHashMap()

Description

Constructs an empty HashMap with the default initial capacity (16) and the default load factor (0.75).

License

Open Source License

Parameter

Parameter Description
K a parameter
V a parameter

Declaration

public static <K, V> Map<K, V> newHashMap() 

Method Source Code


//package com.java2s;

import java.util.HashMap;

import java.util.Map;

public class Main {
    /**/*  ww w  .ja va 2  s .c o m*/
     * Constructs an empty <tt>HashMap</tt> with the default initial capacity
     * (16) and the default load factor (0.75).
     * 
     * @param <K>
     * @param <V>
     * @return
     */
    public static <K, V> Map<K, V> newHashMap() {
        return newHashMap(16);
    }

    /**
     * Constructs an empty HashMap with the specified initial capacity and the default load factor (0.75).
     * 
     * @param <K>
     * @param <V>
     * @param initialCapacity
     * @return
     */
    public static <K, V> Map<K, V> newHashMap(int initialCapacity) {
        return new HashMap<K, V>(initialCapacity);
    }
}

Related

  1. hashMap(Entry... entries)
  2. hashMap(Entry... entries)
  3. hashMap(Object... kvs)
  4. hashMapRange(int upTo)
  5. newHashMap( Map map)
  6. newHashMap()
  7. newHashMap()
  8. newHashMap()
  9. newHashMap()