Here you can find the source of toMap(Object... pairs)
@SuppressWarnings("unchecked") public static <K, V> Map<K, V> toMap(Object... pairs)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { @SuppressWarnings("unchecked") public static <K, V> Map<K, V> toMap(Object... pairs) { Map<K, V> ret = new HashMap<K, V>(); if (pairs == null || pairs.length == 0) return ret; if (pairs.length % 2 != 0) { throw new IllegalArgumentException("Map pairs can not be odd number."); }//from w ww . j a v a2s .com int len = pairs.length / 2; for (int i = 0; i < len; i++) { ret.put((K) pairs[2 * i], (V) pairs[2 * i + 1]); } return ret; } }