Java HashMap Create newHashMap(int size)

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

Description

Create new HashMap .

License

Apache License

Parameter

Parameter Description
size size of HashMap
K keyType
V valueType

Return

created instance

Declaration

public static <K, V> HashMap<K, V> newHashMap(int size) 

Method Source Code

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

import java.util.Collection;
import java.util.HashMap;

import java.util.Map;

public class Main {
    /**/*  w  ww  .  j a  va2s.  c o m*/
     * Create new {@link HashMap}.
     *
     * @param <K> key
     * @param <V> value
     * @return {@link HashMap}
     */
    public static <K, V> Map<K, V> newHashMap() {
        return new HashMap<K, V>();
    }

    /**
     * Create new {@link HashMap}.
     *
     * @param size size of {@link HashMap}
     * @param <K>  keyType
     * @param <V>  valueType
     * @return created {@link HashMap} instance
     */
    public static <K, V> HashMap<K, V> newHashMap(int size) {
        return new HashMap<K, V>(size);
    }

    /**
     * Create new {@link HashMap} having same size of given base collection.
     *
     * @param base collection which size will be referred
     * @param <K>  keyType
     * @param <V>  valueType
     * @return created {@link HashMap} instance
     */
    public static <K, V> HashMap<K, V> newHashMap(Collection<?> base) {
        return new HashMap<K, V>(base.size());
    }
}

Related

  1. newHashMap(final int size)
  2. newHashMap(final K key, final V value)
  3. newHashMap(int capacity)
  4. newHashMap(int size)
  5. newHashMap(int size)
  6. newHashMap(K[] keys, V[] values)
  7. newHashMap(K[] keys, V[] values)
  8. newHashMap(Map.Entry... entries)
  9. newHashMap(Map m)