Determine a new value for an entry within a map.
import public
|
The merge() method either creates a new entry with a specified key and value, or if an entry with the specified key already exists, it calculates a new value for that entry.
The new value is computed using a function, which can be defined by a lambda expression compatible with Java’s BiFunction interface’s apply() method.
public |
K and V denote the data types of the keys and values within the map.
Parameter |
Description |
key |
Required: Specifies the key of the entry. |
value |
Required: Specifies the value to be used if an entry with the specified key does not exist yet. |
function |
Required: A BiFunction object or lambda expression that operates on each entry. The function’s first parameter contains the current value of the entry, and the second parameter contains the value specified by the value argument. |
Returns: |
The value that is stored in the entry. |