Kotlin – Create an Array of Integers

Create an Array of Strings in Kotlin

To create an array of integers in Kotlin, you can use arrayOf() function. Call arrayOf() function and pass the integer elements as arguments to the function. The function returns an Array created from the given integer elements.

Examples

Create an Array of roll numbers

In the following program, we create an array with the roll numbers of students in a class.

Kotlin Program

fun main(args: Array<String>) {
    val rollNumbers = arrayOf(7, 8, 9, 10)
}

Create an Array of Fibonacci series

In the following program, we create an array with the first 10 elements of Fibonacci series as elements of the Array.

Kotlin Program

fun main(args: Array<String>) {
    val fibonacciSeries = arrayOf(0, 1, 1, 2, 3, 5, 8, 13, 21, 34)
}