Here you can find the source of toMap(Object[] array, Map map)
public static Map toMap(Object[] array, Map map)
//package com.java2s; //License from project: Open Source License import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; public class Main { public static Map toMap(Object[] array) { return toMap(array, (Map) null); }//from w w w. j av a 2 s. c om public static Map toMap(Object[] array, Map map) { if (array == null) { return (Map) map; } else { if (map == null) { map = new HashMap((int) ((double) array.length * 1.5D)); } for (int i = 0; i < array.length; ++i) { Object object = array[i]; if (object instanceof Entry) { Entry entry = (Entry) object; ((Map) map).put(entry.getKey(), entry.getValue()); } else { if (!(object instanceof Object[])) { throw new IllegalArgumentException("Array element " + i + ", '" + object + "', is neither of type Map.Entry nor an Array"); } Object[] entry = (Object[]) ((Object[]) object); if (entry.length < 2) { throw new IllegalArgumentException( "Array element " + i + ", '" + object + "', has a length less than 2"); } ((Map) map).put(entry[0], entry[1]); } } return (Map) map; } } }