Kotlin Array.toUIntArray()

Kotlin Array.toUIntArray() Tutorial

The Array.toUIntArray() function in Kotlin is used to convert an Array of UInt type values, into an UIntArray. It creates a new UIntArray containing the elements of the original array.

This is just a conversion of data from Array<UInt> type to UIntArray type.

This tutorial will explore the syntax of the Array.toUIntArray() function and provide examples of its usage in Kotlin arrays.


The syntax of the Array.toUIntArray() function is as follows:

fun Array<out UInt>.toUIntArray(): UIntArray

Examples for Array.toUIntArray() function

1. Convert Array of unsigned integers to UIntArray

In this example, we’ll take an array of unsigned integers in originalArray, and convert this Array into an UIntArray using Array.toUIntArray().

Kotlin Program

fun main() {
    val originalArray: Array<UInt> = arrayOf(100u, 200u, 300u, 400u)

    // Using toUIntArray() to convert the Array of integers to an UIntArray
    val intArray = originalArray.toUIntArray()

    // Printing the original array and the resulting UIntArray
    println("Given Array:\n${originalArray.contentToString()}\n")
    println("UInt Array:\n${intArray.contentToString()}")


Given Array:
[100, 200, 300, 400]

UInt Array:
[100, 200, 300, 400]


In this tutorial, we’ve covered the Array.toUIntArray() function in Kotlin, its syntax, and how to use it to convert an Array of UInt values into an UIntArray.