Java Map Put putIfAbsent(Map map, S key, T val)

Here you can find the source of putIfAbsent(Map map, S key, T val)

Description

put If Absent

License

Apache License

Declaration

public static <S, T> boolean putIfAbsent(Map<S, T> map, S key, T val) 

Method Source Code


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

import java.util.*;

public class Main {
    public static <S, T> boolean putIfAbsent(Map<S, T> map, S key, T val) {
        if (map.containsKey(key))
            return false;
        map.put(key, val);
        return true;
    }/*from w w  w  . ja va 2 s. c o  m*/
}

Related

  1. putIfAbsent(final Map from, final Map to)
  2. putIfAbsent(Map from, Map to)
  3. putIfAbsent(Map map, K key, V value)
  4. putIfAbsent(Map map, K key, V value)
  5. putIfAbsent(Map map, K key, V value)
  6. putIfAbsent(Map map, String name, String value)
  7. putIfAbsentGet(Map map, K key, V value)
  8. putIfNonNull(Map map, K key, V value)
  9. putIfNotExist(Map map, K key, V value)