MapUtil { public static <E> Map<E, E> arrayToMap(E[][] array) { final Map<E, E> map = newHashMap((int) (array.length)); JUtil.fur(0, array.length - 1, 1, i -> { final E[] entry = array[i]; if (entry.length < 2) throw new IllegalArgumentException(String.format("Array element %d, has a length less than 2 .", i)); map.put(entry[0], entry[1]); }); return map; }  static Map<K, V> newHashMap(); static Map<K, V> newHashMap(int initialCapacity); static Map<K, V> newHashMap(int initialCapacity, float loadFactor); static Map<K, V> newHashMap(Map<? extends K, ? extends V> m); @SafeVarargs static Map<K, V> buildHashMap(V... values); @SuppressWarnings("rawtypes") static Class<? extends Map> getHashMapClass(); static Map<K, V> newLinkedHashMap(); static Map<K, V> newLinkedHashMap(int initialCapacity); static Map<K, V> newLinkedHashMap(Map<? extends K, ? extends V> m); @SafeVarargs static Map<K, V> buildLinkedHashMap(V... values); @SuppressWarnings("rawtypes") static Class<? extends Map> getLinkedHashMapClass(); static Map<K, V> newIdentityHashMap(); static Map<K, V> newIdentityHashMap(int initialCapacity); static Map<K, V> newIdentityHashMap(Map<? extends K, ? extends V> m); @SuppressWarnings("rawtypes") static Class<? extends Map> getIdentityHashMapClass(); @SafeVarargs static Map<K, V> buildIdentityHashMap(V... values); static TreeMap<K, V> newTreeMap(); static TreeMap<K, V> newTreeMap(Comparator<? super K> comparator); static TreeMap<K, V> newTreeMap(Map<? extends K, ? extends V> m); static TreeMap<K, V> newTreeMap(SortedMap<K, ? extends V> m); @SafeVarargs static TreeMap<K, V> buildTreeMap(V... values); @SuppressWarnings("rawtypes") static Class<? extends TreeMap> getTreeMapClass(); static Hashtable<K, V> newHashtable(); static Hashtable<K, V> newHashtable(int initialCapacity); static Hashtable<K, V> newHashtable(Map<? extends K, ? extends V> m); @SafeVarargs static Hashtable<K, V> buildHashtable(V... values); @SuppressWarnings("rawtypes") static Class<? extends Hashtable> getHashtableClass(); static Map<E, E> arrayToMap(E[][] array); static boolean isEmpty(Map<?, ?> map);  }
@Test public void testArrayToMap() { String[][] array1 = { { "a", "A" }, { "b", "B" } }; Map<String, String> map1 = MapUtil.arrayToMap(array1); assertEquals(map1.size(), 2); assertEquals(map1.get("a"), "A"); assertEquals(map1.get("b"), "B"); Object[][] array2 = { { "a", 1 }, { "b", 2 } }; Map<Object, Object> map2 = MapUtil.arrayToMap(array2); assertEquals(map2.size(), 2); assertEquals(map2.get("a"), 1); assertEquals(map2.get("b"), 2); }