Update an entry in a map with a newly computed value.
import public
|
The compute() method updates the value of an existing entry or creates a new entry with a computed value if it doesn’t exist.
The new value is calculated using a function, which can be defined with a lambda expression compatible with Java’s BiFunction interface’s apply() method.
public |
K represents the data type of the map’s keys.
Parameter |
Description |
key |
Required: Specifies the key for the entry. |
function |
Required: A BiFunction object or lambda expression that computes the value of the entry. The function’s first parameter is the entry’s key, and the second parameter is its value. |
Returns: |
The value calculated by the function. |