Java Map Create buildMap(K key1, V value1)

Here you can find the source of buildMap(K key1, V value1)

Description

Build Map with 1 pair.

License

Apache License

Parameter

Parameter Description
K key type
V value type
key1 key
value1 value

Return

created map

Declaration

public static <K, V> Map<K, V> buildMap(K key1, V value1) 

Method Source Code


//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;
    }
}

Related

  1. buildMap(K key, V value)
  2. buildMap(List a, Map coeffs)
  3. buildMap(Object key, Object value)
  4. buildMap(Object... data)
  5. buildMap(String... keysAndValues)