Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.HashMap;
import java.util.Map;

public class Main {
    public static <K, V> Map<K, V> arraysToMap(K[] keys, V[] values) {
        if (keys.length != values.length)
            throw new RuntimeException("Lenght of keys: " + keys.length + ", length of values: " + values.length);
        Map<K, V> res = new HashMap<>();
        for (int i = 0; i < keys.length; ++i) {
            res.put(keys[i], values[i]);
        }
        return res;
    }
}