Enumeration.asSequence所在位置是kotlin.sequences / java.util.Enumeration.asSequence,其相關用法介紹如下。

用法:

fun <T> Enumeration<T>.asSequence(): Sequence<T>

創建一個從該枚舉返回所有值的序列。該序列被限製為僅迭代一次。

例子:

import kotlin.test.*

fun main(args: Array<String>) {
//sampleStart
val numbers = java.util.Hashtable<String, Int>()
numbers.put("one", 1)
numbers.put("two", 2)
numbers.put("three", 3)

// when you have an Enumeration from some old code
val enumeration: java.util.Enumeration<String> = numbers.keys()

// you can wrap it in a sequence and transform further with sequence operations
val sequence = enumeration.asSequence().sorted()
println(sequence.toList()) // [one, three, two]

// the resulting sequence is one-shot
// sequence.toList() //  will fail
//sampleEnd
}

輸出:

[one, three, two]