Here you can find the source of createMap(List
Parameter | Description |
---|---|
keys | List of keys |
values | List of values |
Parameter | Description |
---|---|
IllegalArgumentException | When either List is null or the sizes do not equal |
public static Map<Object, Object> createMap(List<Object> keys, List<Object> values)
//package com.java2s; /*/*from ww w . j av a2s. c o m*/ * StringUtils.java * * Copyright (c) 1998 - 2006 BusinessTechnology, Ltd. * All rights reserved * * This program is the proprietary and confidential information * of BusinessTechnology, Ltd. and may be used and disclosed only * as authorized in a license agreement authorizing and * controlling such use and disclosure * * Millennium ERP system. * */ import java.util.HashMap; import java.util.List; import java.util.Map; public class Main { /** * Create a Map from a List of keys and a List of values * * @param keys List of keys * @param values List of values * @return Map of combined lists * @throws IllegalArgumentException When either List is null or the sizes do not equal */ public static Map<Object, Object> createMap(List<Object> keys, List<Object> values) { if (keys == null || values == null || keys.size() != values.size()) { throw new IllegalArgumentException("Keys and Values cannot be null and must be the same size"); } Map<Object, Object> newMap = new HashMap<Object, Object>(); for (int i = 0; i < keys.size(); i++) { newMap.put(keys.get(i), values.get(i)); } return newMap; } }