Java Map Create map(final Entry... entries)

Here you can find the source of map(final Entry... entries)

Description

map

License

Open Source License

Parameter

Parameter Description
entries the <i>final</i> set of entries to add to the newly created <i>unmodifiable</i> map

Return

an unmodifiable map with all given entries

Declaration

public static <K, V> Map<K, V> map(final Entry<K, V>... entries) 

Method Source Code

//package com.java2s;
/*//from   w w w  . ja v  a  2 s. co  m
 * Copyright (C) 2013
 *
 * 52?North Initiative for Geospatial Open Source Software GmbH
 * Contact: Andreas Wytzisk
 * Martin-Luther-King-Weg 24
 * 48155 Muenster, Germany
 * info@52north.org
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

import java.util.Collections;
import java.util.HashMap;

import java.util.Map;
import java.util.Map.Entry;

public class Main {
    /**
     * @param entries the <i>final</i> set of entries to add to the newly created <i>unmodifiable</i> map
     * @return an <i>unmodifiable</i> map with all given entries
     */
    public static <K, V> Map<K, V> map(final Entry<K, V>... entries) {
        final HashMap<K, V> map = new HashMap<K, V>(entries.length);
        for (final Entry<K, V> entry : entries) {
            map.put(entry.getKey(), entry.getValue());
        }
        return Collections.unmodifiableMap(map);
    }

    public static <K, V> Map<K, V> map() {
        return new HashMap<K, V>();
    }

    /**
     * @return an <b>UNMODIFIABLE</b> Map&lt;K, V&gt;
     */
    public static <K, V> Map<K, V> unmodifiableMap(final Map<? extends K, ? extends V> m) {
        return (m == null) ? Collections.<K, V>emptyMap() : Collections.unmodifiableMap(m);
    }
}

Related

  1. createMap_pollutantHourly()
  2. createMapFor(String... args)
  3. createMapFromArgs(Object... args)
  4. createMapFromProperties(Properties stringSubstitutionVariables)
  5. createMapFromWebsiteList(String[] websiteList)
  6. map(final Object... keysAndValues)
  7. map(final Properties props)
  8. map(int initialCapacity)
  9. map(K key, V value)