What does `Map.computeIfAbsent()` do?

Java Professional Medium

Java Professional — Medium

What does `Map.computeIfAbsent()` do?

Key points

  • `computeIfAbsent()` only computes and puts a value if the key is not already present.
  • It returns the new or existing value associated with the key.
  • This method does not return null if the key is absent.

Ready to go further?

Related questions