Freigeben über


IMap.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:Java.Util.IMap, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=24)]
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:Java.Util.IMap, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null", ApiSince=24)>]
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

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:

{@code
            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.

Added in 1.8.

Java documentation for java.util.Map.merge(K, V, java.util.function.BiFunction<? super V, ? super V, ? extends V>).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to