toList

Platform and version requirements: JVM (1.0)
fun <T> Enumeration<T>.toList(): List<T>

Returns a list containing the elements returned by this enumeration in the order they are returned by the enumeration.

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<Int> = numbers.elements()

// you can convert it to list and transform further with list operations
val list = enumeration.toList().sorted()
println(list) // [1, 2, 3]
//sampleEnd
}

© 2010–2021 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/java.util.-enumeration/to-list.html