fetchAndIncrementAt

Atomically increments the element of this AtomicIntArray at the given index by one 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.fetchAndIncrementAt(1)) // 2
println(a.loadAt(1)) // 3
println(a.toString()) // [1, 3, 3] 
   //sampleEnd
}

Atomically increments the element of this AtomicLongArray at the given index by one 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 = AtomicLongArray(longArrayOf(1, 2, 3))
println(a.fetchAndIncrementAt(1)) // 2
println(a.loadAt(1)) // 3
println(a.toString()) // [1, 3, 3] 
   //sampleEnd
}