add
Adds the specified element to the end of this list.
Since Kotlin
1.4Return
true
because the list is always modified as the result of this operation.
Inserts an element into the list at the specified index.
All elements that had indices index .. index + size - 1
are shifted 1 position right.
If index is equal to size, element will be appended to this list.
Since Kotlin
1.4Throws
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = mutableListOf('a', 'b', 'c')
list.add(1, 'c')
println(list) // [a, c, b, c]
list.add(4, 'a')
println(list) // [a, c, b, c, a]
// list.add(100500, 'a') // will fail with IndexOutOfBoundsException
//sampleEnd
}