Java tutorial
//package com.java2s; import java.util.HashMap; public class Main { public static <K, V> HashMap<K, V> createHashMap() { return new HashMap<K, V>(); } public static <K, V> HashMap<K, V> createHashMap(int initialCapacity) { return new HashMap<K, V>(initialCapacity); } public static <K, V> HashMap<K, V> createHashMap(K k, V v) { HashMap<K, V> m = new HashMap<K, V>(); m.put(k, v); return m; } public static <K, V> HashMap<K, V> createHashMap(K k1, V v1, K k2, V v2) { HashMap<K, V> m = new HashMap<K, V>(); m.put(k1, v1); m.put(k2, v2); return m; } public static <K, V> HashMap<K, V> createHashMap(K k1, V v1, K k2, V v2, K k3, V v3) { HashMap<K, V> m = new HashMap<K, V>(); m.put(k1, v1); m.put(k2, v2); m.put(k3, v3); return m; } public static <K, V> HashMap<K, V> createHashMap(K k1, V v1, K k2, V v2, K k3, V v3, K k4, V v4) { HashMap<K, V> m = new HashMap<K, V>(); m.put(k1, v1); m.put(k2, v2); m.put(k3, v3); m.put(k4, v4); return m; } public static <K, V> HashMap<K, V> createHashMap(Object... args) { if (args == null || args.length < 2) { return new HashMap<K, V>(); } HashMap<K, V> m = new HashMap<K, V>(); for (int i = 0; i < args.length; i = i + 2) { m.put((K) args[i], (V) args[i + 1]); } return m; } }