addAll
Adds all of the elements of the specified collection to the end of this list.
The elements are appended in the order they appear in the elements collection.
Since Kotlin
1.4Return
true
if the list was changed as the result of the operation.
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = mutableListOf('a', 'b', 'c')
println("list.addAll(listOf('a', 'b', 'c')) is ${list.addAll(listOf('a', 'b', 'c'))}") // true
println(list) // [a, b, c, a, b, c]
//sampleEnd
}
Inserts all of the elements of the specified collection elements into this list at the specified index.
The elements are inserted in the order they appear in the elements collection.
All elements that initially were stored at indices index .. index + size - 1
are shifted elements.size
positions to the end.
If index is equal to size, elements will be appended to the list.
Since Kotlin
1.4Return
true
if the list was changed as the result of the operation.
Throws
Samples
import kotlin.math.*
import kotlin.test.*
fun main() {
//sampleStart
val list = mutableListOf('a', 'b', 'c')
list.addAll(1, listOf('x', 'y', 'z'))
println(list) // [a, x, y, z, b, c]
list.addAll(6, listOf('h', 'i'))
println(list) // [a, x, y, z, b, c, h, i]
// list.addAll(100500, listOf('z')) // will fail with IndexOutOfBoundsException
//sampleEnd
}