add

expect abstract override fun add(element: E): Boolean(source)

Adds the specified element to the end of this list.

Since Kotlin

1.0

Return

true because the list is always modified as the result of this operation.

Samples

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

fun main() { 
   //sampleStart 
   val list = mutableListOf('a', 'b', 'c')
println("list.add('c') is ${list.add('c')}") // true
println(list) // [a, b, c, c] 
   //sampleEnd
}

expect abstract fun add(index: Int, element: E)(source)

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.0

Throws

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

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
}
actual abstract override fun add(element: E): Boolean(source)

Adds the specified element to the end of this list.

Since Kotlin

1.1

Return

true because the list is always modified as the result of this operation.

Samples

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

fun main() { 
   //sampleStart 
   val list = mutableListOf('a', 'b', 'c')
println("list.add('c') is ${list.add('c')}") // true
println(list) // [a, b, c, c] 
   //sampleEnd
}

actual abstract fun add(index: Int, element: E)(source)

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

Throws

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

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
}
actual abstract override fun add(element: E): Boolean(source)

Adds the specified element to the end of this list.

Since Kotlin

1.0

Return

true because the list is always modified as the result of this operation.

Samples

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

fun main() { 
   //sampleStart 
   val list = mutableListOf('a', 'b', 'c')
println("list.add('c') is ${list.add('c')}") // true
println(list) // [a, b, c, c] 
   //sampleEnd
}

actual abstract fun add(index: Int, element: E)(source)

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.0

Throws

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

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
}
actual abstract override fun add(element: E): Boolean(source)

Adds the specified element to the end of this list.

Since Kotlin

1.3

Return

true because the list is always modified as the result of this operation.

Samples

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

fun main() { 
   //sampleStart 
   val list = mutableListOf('a', 'b', 'c')
println("list.add('c') is ${list.add('c')}") // true
println(list) // [a, b, c, c] 
   //sampleEnd
}

actual abstract fun add(index: Int, element: E)(source)

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

Throws

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

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
}
actual abstract override fun add(element: E): Boolean(source)

Adds the specified element to the end of this list.

Since Kotlin

1.8

Return

true because the list is always modified as the result of this operation.

Samples

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

fun main() { 
   //sampleStart 
   val list = mutableListOf('a', 'b', 'c')
println("list.add('c') is ${list.add('c')}") // true
println(list) // [a, b, c, c] 
   //sampleEnd
}

actual abstract fun add(index: Int, element: E)(source)

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

Throws

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

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
}
actual abstract override fun add(element: E): Boolean(source)

Adds the specified element to the end of this list.

Since Kotlin

1.8

Return

true because the list is always modified as the result of this operation.

Samples

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

fun main() { 
   //sampleStart 
   val list = mutableListOf('a', 'b', 'c')
println("list.add('c') is ${list.add('c')}") // true
println(list) // [a, b, c, c] 
   //sampleEnd
}

actual abstract fun add(index: Int, element: E)(source)

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

Throws

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

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
}