removeAt

abstract 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.1

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
}
abstract override fun removeAt(index: Int): E(source)

Removes an element at the specified index from the list.

This method is redeclared as abstract, because it's not implemented in the base class, so it must be always overridden in the concrete mutable collection implementation.

Since Kotlin

1.1

Return

the element that has been removed.

abstract 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.3

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
}
abstract 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.8

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
}
abstract 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.8

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
}