Create new Hash Map - Java java.util

Java examples for java.util:Collection Creation

Description

Create new Hash Map

Demo Code


//package com.java2s;

import java.util.HashMap;

import java.util.Map;

public class Main {
    public static void main(String[] argv) {
        System.out.println(newHashMap());
    }//from  w w  w  .  j  av  a 2 s  .  c o  m

    public static <K, V> HashMap<K, V> newHashMap() {
        return new HashMap<K, V>();
    }

    public static <K, V> HashMap<K, V> newHashMap(final int initialCapacity) {
        return new HashMap<K, V>(initialCapacity);
    }

    public static <K, V> HashMap<K, V> newHashMap(
            final int initialCapacity, final float loadFactor) {
        return new HashMap<K, V>(initialCapacity, loadFactor);
    }

    public static <K, V> HashMap<K, V> newHashMap(
            final Map<? extends K, ? extends V> m) {
        return new HashMap<K, V>(m);
    }
}

Related Tutorials