Which is the Best Java Web Framework ?

Java 8 - Why Java8 doesn't provide the putIfPresent() function for Map

Because we already have the method replace that does the same thing

Example

Map<String,String> strMap = new HashMap<String,String>();
strMap.put("Key1","Value1");
strMap.put("Key2", "Value2");
strMap.replace("Key3", "Value3");

* Replace method doesn't throw the exception even if the element with specified Key is not already present in the Map and hence exactly replicate the behavior put If Present.


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.