Kotlin Array.toULongArray()

Kotlin Array.toULongArray() Tutorial

The Array.toULongArray() function in Kotlin is used to convert an Array of ULong type values, into a ULongArray. It creates a new ULongArray containing the elements of the given original array.

This is just a conversion of data from Array<ULong> type to ULongArray type.

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

Syntax

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

fun Array<out ULong>.toULongArray(): ULongArray

Examples for Array.toULongArray() function

1. Convert Array of unsigned long integer values to ULongArray

In this example, we’ll take an array of unsigned long integer values in originalArray, and convert this Array into an ULongArray using Array.toULongArray().

Kotlin Program

fun main() {
    val originalArray: Array<ULong> = arrayOf(10000u, 20000u, 30000u, 400000u)

    // Using toULongArray() to convert the Array of unsigned long integers to a ULongArray
    val ulongArray = originalArray.toULongArray()

    // Printing the original array and the resulting ULongArray
    println("Given Array:\n${originalArray.contentToString()}\n")
    println("ULong Array:\n${ulongArray.contentToString()}")
}

Output

Given Array:
[10000, 20000, 30000, 400000]

ULong Array:
[10000, 20000, 30000, 400000]

Summary

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