Which is the Best Java Web Framework ?

Java 8 - Map getOrDefault method

Returns either the value of the specified Key in Map or the Default Value if the Key is not available.

Sample Code 1

Map<String,String> intMap = new HashMap<String,String>();
strMap.put("Key1","Value1");
strMap.put("Key2", "Value2");
System.out.println(strMap.getOrDefault("Key1", "Value5")); // prints Value1

Sample Code 2

Map<String,String> strMap = new HashMap<String,String>();
strMap.put("Key1","Value1");
strMap.put("Key2", "Value2");
System.out.println(strMap.getOrDefault("Key5", "Value5")); // prints Value5


Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus




×

Try our new Java Interview Questions Search Tool.

There are more than 1000 questions with practice tests.

It's updated daily and It's Awesome.


×

Try our new Java Practice Test tool.

There are more than 200 questions and expanding quickly. It's updated daily and It's Awesome.