Java Array to Map toMap(K[] keys, V[] values)

Here you can find the source of toMap(K[] keys, V[] values)

Description

to Map

License

Open Source License

Declaration

public static <K, V> Map<K, V> toMap(K[] keys, V[] values) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.HashMap;

import java.util.Map;

public class Main {

    public static <K, V> Map<K, V> toMap(K[] keys, V[] values) {
        HashMap<K, V> map = new HashMap<K, V>();

        if (keys != null) {
            for (int i = 0; i < keys.length; i++) {
                map.put(keys[i], values != null ? (i < values.length ? values[i] : null) : null);
            }//from w  w  w  .  j a v a 2s . co  m
        }

        return map;
    }
}

Related

  1. arrayToMap(int[] array)
  2. toMap(K[] keys, V[] values)
  3. toMap(String... args)
  4. toMap(String... keysAndValues)
  5. toMap(String[] keyNames, T[] values)
  6. toMap(String[] keys)