Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * 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;
    }
}