Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

computeifabsent hashmap java

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class Test {
    public static void main(String[] s) {
        Map<String, Boolean> whoLetDogsOut = new ConcurrentHashMap<>();
        whoLetDogsOut.computeIfAbsent("snoop", k -> f(k));
        whoLetDogsOut.computeIfAbsent("snoop", k -> f(k));
    }
    static boolean f(String s) {
        System.out.println("creating a value for ""+s+'"');
        return s.isEmpty();
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #computeifabsent #hashmap #java
ADD COMMENT
Topic
Name
9+1 =