remove

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

Removes a single instance of the specified element from this collection, if the collection contains it.

Since Kotlin

1.0

Return

true if the element has been successfully removed; false if it was not contained in the collection.

Samples

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

fun main() { 
   //sampleStart 
   val list = mutableListOf('a', 'b', 'c')

println("list.remove('a') is ${list.remove('a')}") // true
println(list) // [b, c]

// There are no more 'a's to remove
println("list.remove('a') is ${list.remove('a')}") // false
println(list) // [b, c] 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val set = mutableSetOf('a', 'b', 'c')

println("set.remove('a') is ${set.remove('a')}") // true
println(set) // [b, c]

// There are no more 'a's to remove
println("set.remove('a') is ${set.remove('a')}") // false
println(set) // [b, c] 
   //sampleEnd
}
actual abstract override fun remove(element: E): Boolean(source)

Removes a single instance of the specified element from this collection, if the collection contains it.

Since Kotlin

1.1

Return

true if the element has been successfully removed; false if it was not contained in the collection.

Samples

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

fun main() { 
   //sampleStart 
   val list = mutableListOf('a', 'b', 'c')

println("list.remove('a') is ${list.remove('a')}") // true
println(list) // [b, c]

// There are no more 'a's to remove
println("list.remove('a') is ${list.remove('a')}") // false
println(list) // [b, c] 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val set = mutableSetOf('a', 'b', 'c')

println("set.remove('a') is ${set.remove('a')}") // true
println(set) // [b, c]

// There are no more 'a's to remove
println("set.remove('a') is ${set.remove('a')}") // false
println(set) // [b, c] 
   //sampleEnd
}
actual abstract override fun remove(element: E): Boolean(source)

Removes a single instance of the specified element from this collection, if the collection contains it.

Since Kotlin

1.0

Return

true if the element has been successfully removed; false if it was not contained in the collection.

Samples

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

fun main() { 
   //sampleStart 
   val list = mutableListOf('a', 'b', 'c')

println("list.remove('a') is ${list.remove('a')}") // true
println(list) // [b, c]

// There are no more 'a's to remove
println("list.remove('a') is ${list.remove('a')}") // false
println(list) // [b, c] 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val set = mutableSetOf('a', 'b', 'c')

println("set.remove('a') is ${set.remove('a')}") // true
println(set) // [b, c]

// There are no more 'a's to remove
println("set.remove('a') is ${set.remove('a')}") // false
println(set) // [b, c] 
   //sampleEnd
}
actual abstract override fun remove(element: E): Boolean(source)

Removes a single instance of the specified element from this collection, if the collection contains it.

Since Kotlin

1.3

Return

true if the element has been successfully removed; false if it was not contained in the collection.

Samples

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

fun main() { 
   //sampleStart 
   val list = mutableListOf('a', 'b', 'c')

println("list.remove('a') is ${list.remove('a')}") // true
println(list) // [b, c]

// There are no more 'a's to remove
println("list.remove('a') is ${list.remove('a')}") // false
println(list) // [b, c] 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val set = mutableSetOf('a', 'b', 'c')

println("set.remove('a') is ${set.remove('a')}") // true
println(set) // [b, c]

// There are no more 'a's to remove
println("set.remove('a') is ${set.remove('a')}") // false
println(set) // [b, c] 
   //sampleEnd
}
actual abstract override fun remove(element: E): Boolean(source)

Removes a single instance of the specified element from this collection, if the collection contains it.

Since Kotlin

1.8

Return

true if the element has been successfully removed; false if it was not contained in the collection.

Samples

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

fun main() { 
   //sampleStart 
   val list = mutableListOf('a', 'b', 'c')

println("list.remove('a') is ${list.remove('a')}") // true
println(list) // [b, c]

// There are no more 'a's to remove
println("list.remove('a') is ${list.remove('a')}") // false
println(list) // [b, c] 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val set = mutableSetOf('a', 'b', 'c')

println("set.remove('a') is ${set.remove('a')}") // true
println(set) // [b, c]

// There are no more 'a's to remove
println("set.remove('a') is ${set.remove('a')}") // false
println(set) // [b, c] 
   //sampleEnd
}
actual abstract override fun remove(element: E): Boolean(source)

Removes a single instance of the specified element from this collection, if the collection contains it.

Since Kotlin

1.8

Return

true if the element has been successfully removed; false if it was not contained in the collection.

Samples

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

fun main() { 
   //sampleStart 
   val list = mutableListOf('a', 'b', 'c')

println("list.remove('a') is ${list.remove('a')}") // true
println(list) // [b, c]

// There are no more 'a's to remove
println("list.remove('a') is ${list.remove('a')}") // false
println(list) // [b, c] 
   //sampleEnd
}
import kotlin.math.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   val set = mutableSetOf('a', 'b', 'c')

println("set.remove('a') is ${set.remove('a')}") // true
println(set) // [b, c]

// There are no more 'a's to remove
println("set.remove('a') is ${set.remove('a')}") // false
println(set) // [b, c] 
   //sampleEnd
}