Here you can find the source of createMap(Iterable extends Entry
Parameter | Description |
---|---|
entries | a parameter |
public static <K, V> Map<K, V> createMap(Iterable<? extends Entry<K, V>> entries)
//package com.java2s; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; public class Main { /**/*w ww . j a v a 2s . co m*/ * Simple utility to initialize a map with one key/value pair * * @param <K> * @param <V> * @param key * @param value * @return */ public static <K, V> Map<K, V> createMap(K key, V value) { Map<K, V> map = new HashMap<K, V>(); map.put(key, value); return map; } /** * Initialize a map using a variable number of {@link Entry} objects as * input * * @param entries * @return */ public static <K, V> Map<K, V> createMap(Iterable<? extends Entry<K, V>> entries) { Map<K, V> map = new HashMap<K, V>(); for (Entry<K, V> entry : entries) map.put(entry.getKey(), entry.getValue()); return map; } /** * Simple utility to initialize a map with two key/value pairs. * * @param <K> * @param <V> * @param key1 * @param value1 * @param key2 * @param value2 * @return */ public static <K, V> Map<K, V> createMap(K key1, V value1, K key2, V value2) { if (key1.equals(key2)) throw new IllegalArgumentException( "Key1 = Key2, value1 will be overwritten! The createMap method requires unique keys."); Map<K, V> map = new HashMap<K, V>(); map.put(key1, value1); map.put(key2, value2); return map; } /** * Simple utility to initialize a mpa with three key/value pairs. * * @param <K> * @param <V> * @param key1 * @param value1 * @param key2 * @param value2 * @param key3 * @param value3 * @return */ public static <K, V> Map<K, V> createMap(K key1, V value1, K key2, V value2, K key3, V value3) { Map<K, V> map = new HashMap<K, V>(); map.put(key1, value1); map.put(key2, value2); map.put(key3, value3); return map; } }