Here you can find the source of buildMap(K key1, V value1)
Parameter | Description |
---|---|
K | key type |
V | value type |
key1 | key |
value1 | value |
public static <K, V> Map<K, V> buildMap(K key1, V value1)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**/*from w w w. j a va 2 s . c o m*/ * Build Map with 1 pair. * * @param <K> * key type * @param <V> * value type * @param key1 * key * @param value1 * value * @return created map */ public static <K, V> Map<K, V> buildMap(K key1, V value1) { Map<K, V> map = new HashMap<K, V>(1); map.put(key1, value1); return map; } /** * Build Map with 2 pairs. * * @param <K> * key type * @param <V> * value type * @param key1 * key * @param value1 * value * @param key2 * key * @param value2 * value * @return create map */ public static <K, V> Map<K, V> buildMap(K key1, V value1, K key2, V value2) { Map<K, V> map = new HashMap<K, V>(2); map.put(key1, value1); map.put(key2, value2); return map; } /** * Build Map with 3 pairs. * * @param <K> * key type * @param <V> * value type * * @param key1 * key * @param value1 * value * @param key2 * key * @param value2 * value * @param key3 * key * @param value3 * value * @return create map */ public static <K, V> Map<K, V> buildMap(K key1, V value1, K key2, V value2, K key3, V value3) { Map<K, V> map = new HashMap<K, V>(3); map.put(key1, value1); map.put(key2, value2); map.put(key3, value3); return map; } }