HashMap: Java 8 Improvements

Let's discuss the improvements made in the HashMap class in Java 8.

In this lesson, we will look at some of the HashMap operations that were added with Java 8.

The compute() method

The compute(Key, BiFunction) method allows us to update a value in HashMap. This method tries to compute a mapping for the specified key and its current mapped value (or null if no current mapping is found). This method is used to atomically update a value for a given key in HashMap.

  1. If the remapping function passed in compute returns null, the mapping is removed from the Map (or remains absent if initially absent).
  2. If the remapping function throws an exception, the exception is rethrown, and the current
...

Get hands-on with 1400+ tech skills courses.