Java Map Create map(Map accumulator, Key key, Value value)

Here you can find the source of map(Map accumulator, Key key, Value value)

Description

Adds a entry to a map namely (key,value).

License

Open Source License

Parameter

Parameter Description
Key type of the key
Value type of the value
accumulator map to be added to
key to be placed as the single entry
value to be placed as the single entry

Return

map of type Map<Key,Value> with value (key,value).

Declaration


public static <Key, Value> Map<Key, Value> map(Map<Key, Value> accumulator, Key key, Value value) 

Method Source Code

//package com.java2s;
/**//  w  w  w . j a v  a  2s.c o  m
 *  $filename$
 *  Class to create java.util.Map
 *  $Id$
 *
 *  Copyright (c) 2008 by Mutaamba Maasha <maasha@blockfreie.org>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 *  02111-1307, USA.
 **/

import java.util.HashMap;
import java.util.Map;

public class Main {
    /**
     * Adds a entry to a map namely (key,value).
     * 
     * @param <Key>
     *            type of the key
     * @param <Value>
     *            type of the value
     * @param accumulator
     *            map to be added to
     * @param key
     *            to be placed as the single entry
     * @param value
     *            to be placed as the single entry
     * @return map of type Map&lt;Key,Value&gt; with value (key,value).
     */

    public static <Key, Value> Map<Key, Value> map(Map<Key, Value> accumulator, Key key, Value value) {
        accumulator.put(key, value);
        return accumulator;
    }

    /**
     * Constructs a new map with one entry namely (key,value).
     * 
     * @param <Key>
     *            type of the key
     * @param <Value>
     *            type of the value
     * @param key
     *            to be placed as the single entry
     * @param value
     *            to be placed as the single entry
     * @return map of type Map&lt;Key,Value&gt; with value (key,value).
     */
    public static <Key, Value> Map<Key, Value> map(Key key, Value value) {
        Map<Key, Value> result = map();
        result.put(key, value);
        return result;
    }

    /**
     * Constructs a new empty map. A hash map is used.
     * 
     * @param <Key>
     *            type of the key
     * @param <Value>
     *            type of the value
     * @return empty map of type Map&lt;Key,Value&gt
     */
    public static <Key, Value> Map<Key, Value> map() {
        Map<Key, Value> result = new HashMap<Key, Value>();
        return result;
    }
}

Related

  1. map(M map, K key, V value)
  2. map(Map map)
  3. map(Map map, Object key)
  4. map(Map.Entry... entries)
  5. map(Map.Entry... entries)
  6. map(Map outcomeMapping, String line, int firstTabIdx)
  7. map(Object key, Object value)
  8. map(Object obj)
  9. map(Object... args)