Kotlin doubleArrayOf()

Kotlin doubleArrayOf() Function

The Kotlin doubleArrayOf() function is used to create a DoubleArray with the specified values. It provides a concise way to initialize an array of double values.

In this tutorial, you shall learn the syntax of Kotlin doubleArrayOf() function, and how to use it with examples.

Syntax

The syntax of doubleArrayOf() function is

fun doubleArrayOf(vararg elements: Double): DoubleArray

where

ParameterDescription
elementsThe double values to be included in the array.
Parameters of doubleArrayOf() function

The doubleArrayOf() function returns a new DoubleArray containing the specified double values.

Example 1: Creating a Simple DoubleArray

In this example, we’ll use doubleArrayOf() function to create a DoubleArray with a few specified values.

Kotlin Program

fun main() {
    val doubleArray = doubleArrayOf(1.5, 2.0, 3.5, 4.0)
    println("DoubleArray: ${doubleArray.joinToString()}")
}

Output

DoubleArray: 1.5, 2.0, 3.5, 4.0

Summary

In this tutorial, we have seen the syntax of Kotlin doubleArrayOf() function, and how to use it to create a DoubleArray, with examples.