Hashtable.Merge(Object, Object, IBiFunction) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Associates an absent key with a non-null value, or recomputes an existing mapping.
[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=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", 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 value to associate with an absent key or pass to the remapping function for an existing 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 absent and value is non-null, associates the key with that value. If the key is present, replaces the associated value with the result of the given remapping function, or removes the mapping if the result is null. On Android 7 and 7.1, a null value throws NullPointerException. On Android 8 through 17, a null value leaves an absent key unmapped and is passed to the remapping function for a present key. 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. On Android 7 through 13, this method does not check for modifications by the function.
On Android 14 and later, this method will, on a best-effort basis, throw a java.util.ConcurrentModificationException if the remapping function modified this map during computation.
Java reference for java.util.Hashtable.merge.
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.