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.Iterator;
import java.util.List;
import java.util.Map;

public class Main {
    public static <X, Y> Map<X, Y> map(List<X> keys, Iterable<Y> values) {
        Map<X, Y> ret = new HashMap<X, Y>();
        Iterator<X> ks = keys.iterator();
        Iterator<Y> vs = values.iterator();
        while (ks.hasNext()) {
            ret.put(ks.next(), vs.next());
        }
        if (vs.hasNext()) {
            throw new RuntimeException("values is greater than keys");
        }
        return ret;
    }
}