Hervé Lionel Ondoua wrote:Let suppoze that this is the contain of a map m: [jenny=null]
If we apply m.computeIfPresent("jenny", (k,v) -> null), from what I understand the pair key/value is going to be deleted.
That is incorrect. Nothing will happen.
The API documentation of Map.computeIfPresent() explains this:
If the value for the specified key is present and non-null, attempts to compute a new mapping given the key and its current mapped value.
If the function returns null, the mapping is removed. If the function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged.
In your example, the value for the key "jenny" is null, so the mapping function is not called. Since the function is not called at all, the second sentence ("if the function returns null") is not applicable for this case - so the mapping is not removed.
You can try this out for yourself by writing a small program:
Note that on the second line, you see that the entry is still there; it has not been deleted.