Here you can find the source of newHashMap(K[] keys, V[] values)
Parameter | Description |
---|---|
keys | The array of keys. |
values | The array of values. |
public static <K, V> Map<K, V> newHashMap(K[] keys, V[] values)
//package com.java2s; //License from project: Apache License import java.util.HashMap; import java.util.Map; public class Main { /**//from w w w. j a v a2 s . c o m * Create a new hash map and fills it from the given keys and values (keys[index] -> values[index]. * * @param keys The array of keys. * @param values The array of values. * @return A map that contains for each key element in the keys array a value from the values array at the same index. */ public static <K, V> Map<K, V> newHashMap(K[] keys, V[] values) { Map<K, V> map = new HashMap<K, V>(); if (keys == null || values == null || keys.length != values.length) { throw new IllegalArgumentException("keys and values must be non-null and have the same size."); } for (int i = 0; i < keys.length; i++) { map.put(keys[i], values[i]); } return map; } }