IConcurrentMap.PutIfAbsent(Object, Object) Method

Definition

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

[Android.Runtime.Register("putIfAbsent", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", "GetPutIfAbsent_Ljava_lang_Object_Ljava_lang_Object_Handler:Java.Util.Concurrent.IConcurrentMapInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public Java.Lang.Object? PutIfAbsent (Java.Lang.Object? key, Java.Lang.Object? value);
[<Android.Runtime.Register("putIfAbsent", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", "GetPutIfAbsent_Ljava_lang_Object_Ljava_lang_Object_Handler:Java.Util.Concurrent.IConcurrentMapInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member PutIfAbsent : Java.Lang.Object * Java.Lang.Object -> Java.Lang.Object

Parameters

key
Object

key with which the specified value is to be associated

value
Object

value to be associated with the specified key

Returns

the previous value associated with the specified key, or null if there was no mapping for the key. (A null return can also indicate that the map previously associated null with the key, if the implementation supports null values.)

Implements

Attributes

Remarks

If the specified key is not already associated with a value, associates it with the given value. This is equivalent to, for this map:

{@code
            if (!map.containsKey(key))
              return map.put(key, value);
            else
              return map.get(key);}

except that the action is performed atomically.

Java documentation for java.util.concurrent.ConcurrentMap.putIfAbsent(K, 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