Here you can find the source of toMap(Object... data)
@SuppressWarnings({ "unchecked" }) public static <K, V> Map<K, V> toMap(Object... data)
//package com.java2s; import java.util.*; public class Main { @SuppressWarnings({ "unchecked" }) public static <K, V> Map<K, V> toMap(Object... data) { if (data.length % 2 != 0) { throw new IllegalArgumentException("data length: " + data.length);//from w w w . j av a2s . com } Map map = new HashMap(); for (int i = 0; i < data.length; i += 2) { map.put(data[i], data[i + 1]); } return map; } }