Here you can find the source of putIfNotExist(Map
public static <K, V> void putIfNotExist(Map<K, V> map, K key, V value)
//package com.java2s; import java.util.Map; public class Main { public static <K, V> void putIfNotExist(Map<K, V> map, K key, V value) { if (!map.containsKey(key)) { map.put(key, value);/*from w ww .j a va2 s . c o m*/ } } }