Java Map Put putIfNotExists(Map map, K key, V value)

Here you can find the source of putIfNotExists(Map map, K key, V value)

Description

put If Not Exists

License

Apache License

Declaration

@SuppressWarnings("unchecked")
    static <K, V> V putIfNotExists(Map<? super K, ? super V> map, K key, V value) 

Method Source Code

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

import java.util.Map;

public class Main {
    @SuppressWarnings("unchecked")
    static <K, V> V putIfNotExists(Map<? super K, ? super V> map, K key, V value) {
        if (!map.containsKey(key)) {
            map.put(key, value);//from  www .  j a  v  a  2s .co  m
        }
        return (V) map.get(key);
    }
}

Related

  1. putIfAbsent(Map map, String name, String value)
  2. putIfAbsentGet(Map map, K key, V value)
  3. putIfNonNull(Map map, K key, V value)
  4. putIfNotExist(Map map, K key, V value)
  5. putIfNotExists(final K key, final V value, final Map map)
  6. putIfNotNull(final Map map, final String name, final String value)
  7. putIfNotNull(Map map, K key, V value)
  8. putIfNotNull(Map> params, String key, T value)
  9. putIfNotNullAndTrue(Map map, String key, Boolean boolValue)