Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.util.ArrayList;

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

public class Main {
    /**
     * @param <K>
     * @param <V>
     * @param aMap
     * @param aKey
     * @param aValue
     * @return {@link List} to which value was added
     */
    public static <K, V> List<V> addToValueList(Map<K, List<V>> aMap, K aKey, V aValue) {
        List<V> valueList = aMap.get(aKey);
        if (valueList == null) {
            valueList = new ArrayList<>();
            aMap.put(aKey, valueList);
        }

        valueList.add(aValue);
        return valueList;
    }
}