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. The
     * method ignores null values
     *
     * @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) {
        if (newValue == null) {
            return;
        }
        map.computeIfAbsent(key, k -> new LinkedHashSet<>()).add(newValue);
    }
}