mutableSetOf

inline fun <T> mutableSetOf(): MutableSet<T>

Returns an empty new MutableSet.

The returned set preserves the element iteration order.

Since Kotlin

1.1

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val set = mutableSetOf<Int>()
assertTrue(set.isEmpty())

set.add(1)
set.add(2)
set.add(1)

assertPrints(set, "[1, 2]") 
   //sampleEnd
}

fun <T> mutableSetOf(vararg elements: T): MutableSet<T>

Returns a new MutableSet with the given elements. Elements of the set are iterated in the order they were specified.

Samples

import samples.*
import kotlin.test.*
fun main() { 
   //sampleStart 
   val set = mutableSetOf(1, 2, 3)
assertPrints(set, "[1, 2, 3]")

set.remove(3)
set += listOf(4, 5)
assertPrints(set, "[1, 2, 4, 5]") 
   //sampleEnd
}