Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: LGPL 

import java.util.LinkedHashSet;

import java.util.Map;
import java.util.Set;

public class Main {
    /**
     * Adds the value to map. If the key does not exists new value set is created and the value is
     * added to it
     * 
     * @param <K>
     *            the key type
     * @param <V>
     *            the value type
     * @param map
     *            the map
     * @param key
     *            the key
     * @param newValue
     *            the new value
     */
    public static <K, V> void addValueToSetMap(Map<K, Set<V>> map, K key, V newValue) {
        Set<V> list = map.get(key);
        if (list == null) {
            list = new LinkedHashSet<V>();
            map.put(key, list);
        }
        list.add(newValue);
    }
}