Java Map Add addToListMap(Map> map, String key, String value)

Here you can find the source of addToListMap(Map> map, String key, String value)

Description

Adds another element to the Map: The list of strings is enlarged

License

Open Source License

Parameter

Parameter Description
map a parameter
key Key as String
value additional value to be added (at end)

Declaration

public static void addToListMap(Map<String, List<String>> map,
        String key, String value) 

Method Source Code

//package com.java2s;
/*//from w  w  w  .ja v a  2  s  . co  m
 * ******************************************************************************
 * MontiCore Language Workbench
 * Copyright (c) 2015, MontiCore, All rights reserved.
 *
 * This project is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3.0 of the License, or (at your option) any later version.
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this project. If not, see <http://www.gnu.org/licenses/>.
 * ******************************************************************************
 */

import java.util.ArrayList;

import java.util.List;
import java.util.Map;

public class Main {
    /**
     * Adds another element to the Map:
     * The list of strings is enlarged 
     * @param map
     * @param key   Key as String
     * @param value additional value to be added (at end)
     */
    public static void addToListMap(Map<String, List<String>> map,
            String key, String value) {
        List<String> currentList;
        if (map.containsKey(key)) {
            currentList = map.get(key);
        } else {
            currentList = new ArrayList<String>();
        }
        currentList.add(value);
        map.put(key, currentList);
    }
}

Related

  1. addTo(Map map, N key, E element, Class collectionClass)
  2. addToAnd(T target, Map... items)
  3. addToList(Map> map, X key, Y value)
  4. addToListMap(Map map, Object key, Object value)
  5. addToListMap(Map> map, K key, V value)
  6. addToListMap(Map> map, T key, T value)
  7. addToListMap(Map> map, T key, V val)
  8. addToListMap(Map> map, TKey key, TValue value)
  9. addToMap(Map map, int initialKey, T value)