removeAt

open override fun removeAt(index: Int): E(source)

Removes an element at the specified index from the list.

All elements placed after index are shifted 1 position left.

Since Kotlin

1.4

Return

the element that has been removed.

Throws

if index is less than zero or greater than or equal to size of this list.

Samples

import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val list = mutableListOf('a', 'b', 'c')

list.removeAt(1)
println(list) // [a, c]

list.removeAt(0)
println(list) // [c]

// list.removeAt(1) // will fail with IndexOutOfBoundsException 
   //sampleEnd
}