package com.concretepage;
import java.util.HashMap;
public class HashMapPutIfAbsentExample {
public static void main(String[] args) {
HashMap<Integer, String> map = test();
String mapAgain = map.putIfAbsent(4,"Five");
System.out.println(mapAgain);
String result = map.putIfAbsent(73654,"Darwin Bocalbos");
System.out.println(result);
}
private static HashMap<Integer, String> test(){
HashMap<Integer,String> hmapAgain = new HashMap();
hmapAgain.put(1,"One");
hmapAgain.put(2,"Two");
hmapAgain.put(3,"Three");
hmapAgain.put(4,"Four");
hmapAgain.put(73654,"Shyras Travels");
return hmapAgain;
}
}
import java.util.HashMap;
public class HashMapPutIfAbsentExample {
public static void main(String[] args) {
HashMap<Integer, String> map = test();
String mapAgain = map.putIfAbsent(4,"Five");
System.out.println(mapAgain);
String result = map.putIfAbsent(73654,"Darwin Bocalbos");
System.out.println(result);
}
private static HashMap<Integer, String> test(){
HashMap<Integer,String> hmapAgain = new HashMap();
hmapAgain.put(1,"One");
hmapAgain.put(2,"Two");
hmapAgain.put(3,"Three");
hmapAgain.put(4,"Four");
hmapAgain.put(73654,"Shyras Travels");
return hmapAgain;
}
}
No comments:
Post a Comment