W3cubDocs

/Kotlin

emptySet

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
fun <T> emptySet(): 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
}

© 2010–2020 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/empty-set.html