Here you can find the source of putIfNotExists(final K key, final V value, final Map
Parameter | Description |
---|---|
key | a parameter |
value | a parameter |
map | a parameter |
true
if the item was successfully put, otherwise false
public static <K, V extends Object> boolean putIfNotExists(final K key, final V value, final Map<K, V> map)
//package com.java2s; //License from project: Apache License import java.util.Map; public class Main { /**//from w w w . j a va 2 s . c o m * Puts a value with a key into a map if the key is previously unset. * * @param key * @param value * @param map * @return <code>true</code> if the item was successfully put, otherwise * <code>false</code> */ public static <K, V extends Object> boolean putIfNotExists(final K key, final V value, final Map<K, V> map) { if (!map.containsKey(key)) { map.put(key, value); return true; } else { return false; } } }