Kotlin Program to Convert Array to Set (HashSet) and Vice-Versa. The collection object has a constructor that accepts a Collection object to initial the value. Since both Set and List are extended the Collection, the conversion is quite straightforward.
Kotlin Program to Convert Array to Set HashSet and Vice-Versa
Source Code
import java.util.*
fun main(args: Array<String>) {
val array = arrayOf("c", "d", "f")
val set = HashSet(Arrays.asList(*array))
println("Set: $set")
}
Output
Kotlin Program to Convert Array to Set HashSet and Vice-Versa