Here you can find the source of map(K key, V value, Object... keysValues)
Parameter | Description |
---|---|
key | first key of the map |
value | first value of the map |
keysValues | pairs of key value Example: sMap(1, 2, 2, 4) will create {1 -> 2, 2 -> 4} |
@SuppressWarnings("unchecked") public static <K, V> Map<K, V> map(K key, V value, Object... keysValues)
//package com.java2s; //License from project: Apache License import java.util.HashMap; import java.util.Map; public class Main { /**// www.j av a2 s .c o m * Creates the HashMap of Integers * * @param key first key of the map * @param value first value of the map * @param keysValues pairs of key value * Example: sMap(1, 2, 2, 4) will create {1 -> 2, 2 -> 4} * @return new HashMap of String -> String */ @SuppressWarnings("unchecked") public static <K, V> Map<K, V> map(K key, V value, Object... keysValues) { Map<K, V> res = new HashMap<>(); res.put(key, value); if (keysValues.length > 0) { if (keysValues.length % 2 > 0) { throw new IllegalArgumentException("Arguments count must be even!"); } for (int i = 0; i < keysValues.length; i += 2) { K k = (K) keysValues[i]; V v = (V) keysValues[i + 1]; res.put(k, v); } } return res; } }