computeifabsent hashmap java

Solutions on MaxInterview for computeifabsent hashmap java by the best coders in the world

showing results for - "computeifabsent hashmap java"
Émilie
22 Apr 2016
1import java.util.Map;
2import java.util.concurrent.ConcurrentHashMap;
3
4public class Test {
5    public static void main(String[] s) {
6        Map<String, Boolean> whoLetDogsOut = new ConcurrentHashMap<>();
7        whoLetDogsOut.computeIfAbsent("snoop", k -> f(k));
8        whoLetDogsOut.computeIfAbsent("snoop", k -> f(k));
9    }
10    static boolean f(String s) {
11        System.out.println("creating a value for \""+s+'"');
12        return s.isEmpty();
13    }
14}