Language

TreeMap.Merge(Object, Object, IBiFunction) Method

Definition

If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value.

[Android.Runtime.Register("merge", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;", "GetMerge_Ljava_lang_Object_Ljava_lang_Object_Ljava_util_function_BiFunction_Handler", ApiSince=35)]
public virtual Java.Lang.Object? Merge(Java.Lang.Object? key, Java.Lang.Object value, Java.Util.Functions.IBiFunction remappingFunction);
[<Android.Runtime.Register("merge", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;", "GetMerge_Ljava_lang_Object_Ljava_lang_Object_Ljava_util_function_BiFunction_Handler", ApiSince=35)>]
abstract member Merge : Java.Lang.Object * Java.Lang.Object * Java.Util.Functions.IBiFunction -> Java.Lang.Object
override this.Merge : Java.Lang.Object * Java.Lang.Object * Java.Util.Functions.IBiFunction -> Java.Lang.Object

Parameters

key
Object

key with which the resulting value is to be associated

value
Object

the non-null value to be merged with the existing value associated with the key or, if no existing value or a null value is associated with the key, to be associated with the key

remappingFunction
IBiFunction

the remapping function to recompute a value if present

Returns

the new value associated with the specified key, or null if no value is associated with the key

Implements

Attributes

Remarks

If the specified key is not already associated with a value or is associated with null, associates it with the given non-null value. Otherwise, replaces the associated value with the results of the given remapping function, or removes if the result is null. This method may be of use when combining multiple mapped values for a key. For example, to either create or append a String msg to a value mapping:

map.merge(key, msg, String::concat)

If the remapping function returns null, the mapping is removed. If the remapping function itself throws an (unchecked) exception, the exception is rethrown, and the current mapping is left unchanged. The remapping function should not modify this map during computation. This method will, on a best-effort basis, throw a ConcurrentModificationException if it is detected that the remapping function modifies this map during computation.

Java reference for java.util.TreeMap.merge.

Applies to