asSequence

JVM
1.0
fun <T> Enumeration<T>.asSequence(): Sequence<T>
(source)

Creates a sequence that returns all values from this enumeration. The sequence is constrained to be iterated only once.

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
}