fun <T> setOf(vararg elements: T): Set<T>
Returns a new read-only set with the given elements. Elements of the set are iterated in the order they were specified. The returned set is serializable (JVM).
inline fun <T> setOf(): Set<T>
Returns an empty read-only set. The returned set is serializable (JVM).
import kotlin.test.*
fun main(args: Array<String>) {
//sampleStart
val set = setOf<String>()
println("set.isEmpty() is ${set.isEmpty()}") // true
// another way to create an empty set,
// type parameter is inferred from the expected type
val other: Set<Int> = emptySet()
// Empty sets are equal
println("set == other is ${set == other}") // true
println(set) // []
//sampleEnd
}
fun <T> setOf(element: T): Set<T>
Returns an immutable set containing only the specified object element. The returned set is serializable.
© 2010–2018 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/set-of.html