Here you can find the source of addToListMap(Map
Parameter | Description |
---|---|
map | a parameter |
key | Key as String |
value | additional value to be added (at end) |
public static void addToListMap(Map<String, List<String>> map, String key, String value)
//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); } }