111. Computing whether absent/present in a map

Sometimes, a Map doesn't contain the exact out-of-the-box entry that we need. Moreover, when an entry is absent, returning a default entry is not an option as well. Basically, there are cases when we need to compute our entry.

For such cases, JDK 8 comes with a bunch of methods: compute(), computeIfAbsent(), computeIfPresent(), and merge(). Choosing between these methods is a matter of knowing each of them very well.

Let's now take a look at the implementation of these methods using examples.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset