Java Map from Array toMap(Object[] keys, Object[] values)

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

Description

to Map

License

Open Source License

Declaration

public static Map toMap(Object[] keys, Object[] values) 

Method Source Code

//package com.java2s;
/*//from w  w  w .j  a  v  a 2s  . c o  m
 * Copyright 2001-2008 Aqris Software AS. All rights reserved.
 * 
 * This program is dual-licensed under both the Common Development
 * and Distribution License ("CDDL") and the GNU General Public
 * License ("GPL"). You may elect to use one or the other of these
 * licenses.
 */

import java.util.HashMap;

import java.util.Map;

public class Main {
    public static final Map EMPTY_MAP = new HashMap(0);

    public static Map toMap(Object[] keys, Object[] values) {
        if (keys == null || values == null) {
            return EMPTY_MAP;
        }

        return toMap(new HashMap(keys.length), keys, values);
    }

    public static Map toMap(Map map, Object[] keys, Object[] values) {
        if (keys == null || values == null) {
            return map;
        }
        for (int i = 0, max = Math.min(keys.length, values.length); i < max; i++) {
            map.put(keys[i], values[i]);
        }

        return map;
    }
}

Related

  1. toMap(Object... pairs)
  2. toMap(Object... pairs)
  3. toMap(Object[] array)
  4. toMap(Object[] array)
  5. toMap(Object[] array, Map map)
  6. toMap(Object[][] array)