IMap.Compute(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.
Attempts to compute a mapping for the specified key and its current
mapped value (or null
if there is no current mapping).
[Android.Runtime.Register("compute", "(Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;", "GetCompute_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? Compute (Java.Lang.Object? key, Java.Util.Functions.IBiFunction remappingFunction);
[<Android.Runtime.Register("compute", "(Ljava/lang/Object;Ljava/util/function/BiFunction;)Ljava/lang/Object;", "GetCompute_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 Compute : Java.Lang.Object * Java.Util.Functions.IBiFunction -> Java.Lang.Object
override this.Compute : Java.Lang.Object * Java.Util.Functions.IBiFunction -> Java.Lang.Object
Parameters
- key
- Object
key with which the specified value is to be associated
- remappingFunction
- IBiFunction
the remapping function to compute a value
Returns
the new value associated with the specified key, or null if none
- Attributes
Remarks
Attempts to compute a mapping for the specified key and its current mapped value (or null
if there is no current mapping). For example, to either create or append a String
msg to a value mapping:
{@code
map.compute(key, (k, v) -> (v == null) ? msg : v.concat(msg))}
(Method #merge merge()
is often simpler to use for such purposes.)
If the remapping function returns null
, the mapping is removed (or remains absent if initially absent). 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.
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.