Here you can find the source of toMap(Object... objects)
public static final <K, V> Map<K, V> toMap(Object... objects)
//package com.java2s; //License from project: Apache License import java.util.HashMap; import java.util.Map; public class Main { public static final <K, V> Map<K, V> toMap(Object... objects) { if (objects == null || objects.length % 2 != 0) throw new IllegalArgumentException( "Illegal arguments provided to construct a map"); Map<K, V> ret = new HashMap<K, V>(); for (int i = 0; i < objects.length; i += 2) { ret.put((K) objects[i], (V) objects[i + 1]); }/*from w w w .j a v a2s. c o m*/ return ret; } }