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