addAll

expect abstract override fun addAll(elements: Collection<E>): Boolean(source)

Adds all of the elements of the specified collection to this collection.

Since Kotlin

1.0

Return

true if any of the specified elements was added to the collection, false if the collection was not modified.

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
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val set = mutableSetOf('a', 'b', 'c')
// All three elements are in set, nothing will be added
println("set.addAll(listOf('a', 'b', 'c')) is ${set.addAll(listOf('a', 'b', 'c'))}") // false
// At least one element will be added, 'd'
println("set.addAll(listOf('a', 'b', 'c', 'd')) is ${set.addAll(listOf('a', 'b', 'c', 'd'))}") // true
println(set) // [a, b, c, d] 
   //sampleEnd
}
actual abstract override fun addAll(elements: Collection<E>): Boolean(source)

Adds all of the elements of the specified collection to this collection.

Since Kotlin

1.1

Return

true if any of the specified elements was added to the collection, false if the collection was not modified.

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
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val set = mutableSetOf('a', 'b', 'c')
// All three elements are in set, nothing will be added
println("set.addAll(listOf('a', 'b', 'c')) is ${set.addAll(listOf('a', 'b', 'c'))}") // false
// At least one element will be added, 'd'
println("set.addAll(listOf('a', 'b', 'c', 'd')) is ${set.addAll(listOf('a', 'b', 'c', 'd'))}") // true
println(set) // [a, b, c, d] 
   //sampleEnd
}
actual abstract override fun addAll(elements: Collection<E>): Boolean(source)

Adds all of the elements of the specified collection to this collection.

Since Kotlin

1.0

Return

true if any of the specified elements was added to the collection, false if the collection was not modified.

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
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val set = mutableSetOf('a', 'b', 'c')
// All three elements are in set, nothing will be added
println("set.addAll(listOf('a', 'b', 'c')) is ${set.addAll(listOf('a', 'b', 'c'))}") // false
// At least one element will be added, 'd'
println("set.addAll(listOf('a', 'b', 'c', 'd')) is ${set.addAll(listOf('a', 'b', 'c', 'd'))}") // true
println(set) // [a, b, c, d] 
   //sampleEnd
}
actual abstract override fun addAll(elements: Collection<E>): Boolean(source)

Adds all of the elements of the specified collection to this collection.

Since Kotlin

1.3

Return

true if any of the specified elements was added to the collection, false if the collection was not modified.

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
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val set = mutableSetOf('a', 'b', 'c')
// All three elements are in set, nothing will be added
println("set.addAll(listOf('a', 'b', 'c')) is ${set.addAll(listOf('a', 'b', 'c'))}") // false
// At least one element will be added, 'd'
println("set.addAll(listOf('a', 'b', 'c', 'd')) is ${set.addAll(listOf('a', 'b', 'c', 'd'))}") // true
println(set) // [a, b, c, d] 
   //sampleEnd
}
actual abstract override fun addAll(elements: Collection<E>): Boolean(source)

Adds all of the elements of the specified collection to this collection.

Since Kotlin

1.8

Return

true if any of the specified elements was added to the collection, false if the collection was not modified.

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
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val set = mutableSetOf('a', 'b', 'c')
// All three elements are in set, nothing will be added
println("set.addAll(listOf('a', 'b', 'c')) is ${set.addAll(listOf('a', 'b', 'c'))}") // false
// At least one element will be added, 'd'
println("set.addAll(listOf('a', 'b', 'c', 'd')) is ${set.addAll(listOf('a', 'b', 'c', 'd'))}") // true
println(set) // [a, b, c, d] 
   //sampleEnd
}
actual abstract override fun addAll(elements: Collection<E>): Boolean(source)

Adds all of the elements of the specified collection to this collection.

Since Kotlin

1.8

Return

true if any of the specified elements was added to the collection, false if the collection was not modified.

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
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val set = mutableSetOf('a', 'b', 'c')
// All three elements are in set, nothing will be added
println("set.addAll(listOf('a', 'b', 'c')) is ${set.addAll(listOf('a', 'b', 'c'))}") // false
// At least one element will be added, 'd'
println("set.addAll(listOf('a', 'b', 'c', 'd')) is ${set.addAll(listOf('a', 'b', 'c', 'd'))}") // true
println(set) // [a, b, c, d] 
   //sampleEnd
}