exchangeAt

expect fun exchangeAt(index: Int, newValue: Int): Int(source)

Atomically stores the new value into the element of this AtomicIntArray at the given index and returns the old value of the element.

Since Kotlin

2.1

Throws

if the index is out of bounds of this array.

Samples

import kotlin.concurrent.atomics.*

fun main() { 
   //sampleStart 
   val a = AtomicIntArray(intArrayOf(1, 2, 3))
println(a.exchangeAt(1, 7)) // 2
println(a.loadAt(1)) // 7
println(a.toString()) // [1, 7, 3] 
   //sampleEnd
}
actual fun exchangeAt(index: Int, newValue: Int): Int(source)

Atomically stores the new value into the element of this AtomicIntArray at the given index and returns the old value of the element.

Since Kotlin

2.1

Throws

if the index is out of bounds of this array.

actual fun exchangeAt(index: Int, newValue: Int): Int(source)

Atomically stores the new value into the element of this AtomicIntArray at the given index and returns the old value of the element.

Has the same memory effects as java.util.concurrent.atomic.AtomicIntegerArray.getAndSet.

Since Kotlin

2.1

Throws

if the index is out of bounds of this array.

actual fun exchangeAt(index: Int, newValue: Int): Int(source)

Atomically stores the new value into the element of this AtomicIntArray at the given index and returns the old value of the element.

Since Kotlin

2.1

Throws

if the index is out of bounds of this array.

actual fun exchangeAt(index: Int, newValue: Int): Int(source)

Atomically stores the new value into the element of this AtomicIntArray at the given index and returns the old value of the element.

Since Kotlin

2.1

Throws

if the index is out of bounds of this array.

actual fun exchangeAt(index: Int, newValue: Int): Int(source)

Atomically stores the new value into the element of this AtomicIntArray at the given index and returns the old value of the element.

Since Kotlin

2.1

Throws

if the index is out of bounds of this array.