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>) {
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) // []

© 2010–2019 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.