Share via


IConcurrentMap.Replace Method

Definition

Overloads

Replace(Object, Object)

Replaces the entry for a key only if currently mapped to some value.

Replace(Object, Object, Object)

Replaces the entry for a key only if currently mapped to a given value.

Replace(Object, Object)

Replaces the entry for a key only if currently mapped to some value.

[Android.Runtime.Register("replace", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", "GetReplace_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? Replace (Java.Lang.Object? key, Java.Lang.Object? value);
[<Android.Runtime.Register("replace", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", "GetReplace_Ljava_lang_Object_Ljava_lang_Object_Handler:Java.Util.Concurrent.IConcurrentMapInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member Replace : Java.Lang.Object * Java.Lang.Object -> Java.Lang.Object

Parameters

key
Object

key with which the specified value is 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

Replaces the entry for a key only if currently mapped to some value. This is equivalent to, for this map:

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

except that the action is performed atomically.

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

Replace(Object, Object, Object)

Replaces the entry for a key only if currently mapped to a given value.

[Android.Runtime.Register("replace", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Z", "GetReplace_Ljava_lang_Object_Ljava_lang_Object_Ljava_lang_Object_Handler:Java.Util.Concurrent.IConcurrentMapInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")]
public bool Replace (Java.Lang.Object? key, Java.Lang.Object? oldValue, Java.Lang.Object? newValue);
[<Android.Runtime.Register("replace", "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;)Z", "GetReplace_Ljava_lang_Object_Ljava_lang_Object_Ljava_lang_Object_Handler:Java.Util.Concurrent.IConcurrentMapInvoker, Mono.Android, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")>]
abstract member Replace : Java.Lang.Object * Java.Lang.Object * Java.Lang.Object -> bool

Parameters

key
Object

key with which the specified value is associated

oldValue
Object

value expected to be associated with the specified key

newValue
Object

value to be associated with the specified key

Returns

true if the value was replaced

Implements

Attributes

Remarks

Replaces the entry for a key only if currently mapped to a given value. This is equivalent to, for this map:

{@code
            if (map.containsKey(key)
                && Objects.equals(map.get(key), oldValue)) {
              map.put(key, newValue);
              return true;
            } else {
              return false;
            }}

except that the action is performed atomically.

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