The toULongArray() extension function in Kotlin returns an array of ULong containing all of the elements of the collection.
The syntax of Set.toULongArray() extension function is:
fun Collection<ULong>.toULongArray(): ULongArray
This toULongArray() extension function of Set returns an array of ULong containing all of the elements of this collection.
Set.toULongArray() returns value of type ULongArray
.
Using toULongArray() to convert a set of ULong values to a ULongArray.
For example,
fun main() {
val ulongSet = setOf<ULong>(1uL, 2uL, 3uL)
val ulongArray = ulongSet.toULongArray()
println(ulongArray.joinToString())
}
1, 2, 3
Using toULongArray() to handle an empty set of ULong values.
For example,
fun main() {
val emptySet = emptySet<ULong>()
val ulongArray = emptySet.toULongArray()
println(ulongArray.joinToString())
}
Using toULongArray() to convert a set of mixed ULong values to a ULongArray.
For example,
fun main() {
val mixedSet = setOf<ULong>(1uL, 2uL, 18446744073709551615uL)
val ulongArray = mixedSet.toULongArray()
println(ulongArray.joinToString())
}
1, 2, 18446744073709551615
In this Kotlin tutorial, we learned about toULongArray() extension function of Set: the syntax and few working examples with output and detailed explanation for each example.