Java HashMap Create createHashMap(int size)

Here you can find the source of createHashMap(int size)

Description

Creates the hash map instance that will hold the given amount of elements.

License

LGPL

Parameter

Parameter Description
K the key type
V the value type
size the preferred size

Return

the map instance

Declaration

public static <K, V> Map<K, V> createHashMap(int size) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.util.HashMap;

import java.util.Map;

public class Main {
    /**// ww w . j  a  v a 2 s  . co m
     * Creates the hash map instance that will hold the given amount of elements. The returned
     * instance is optimized for that size and will not grow until the given number of elements are
     * added.
     * <p>
     * The method is same as <code>new HashMap<K, V>((int) (size * 1.1), 0.95f)</code>
     * 
     * @param <K>
     *            the key type
     * @param <V>
     *            the value type
     * @param size
     *            the preferred size
     * @return the map instance
     */
    public static <K, V> Map<K, V> createHashMap(int size) {
        return new HashMap<K, V>((int) (size * 1.1), 0.95f);
    }
}

Related

  1. createHashMap()
  2. createHashMap()
  3. createHashMap(int expectedMapSize)
  4. createHashMap(int initialCapacity)
  5. createHashMap(int initialCapacity)
  6. createHashMap(Object key, Object value)
  7. createHashMapIfNull(Map map)
  8. createHashMapWithSize(final int size)
  9. getHashMap()