Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to initial BooleanArray by specific size

Tags:

arrays

kotlin

I have read Kotlin doc

<init>(size: Int, init: (Int) -> Boolean)

Creates a new array of the specified size, where each element is calculated by calling the specified init function.

The function init is called for each array element sequentially starting from the first one. It should return the value for an array element given its index.

Common JVM JS Native (size: Int) Creates a new array of the specified size, with all elements initialized to false.

Constructor Creates a new array of the specified size, with all elements initialized to false.

<init>(size: Int)

Creates a new array of the specified size, with all elements initialized to false.

Constructor Creates a new array of the specified size, with all elements initialized to false.

also try simple code

var booleanArray = <init>(30)

it still not working. any help?

like image 504
UmAnusorn Avatar asked Jan 22 '26 06:01

UmAnusorn


1 Answers

In the documentation, <init> refers to a constructor. You should replace it with the name of the class, which is how you call a constructor. In this case:

var booleanArray = BooleanArray(30)
like image 78
Tenfour04 Avatar answered Jan 24 '26 19:01

Tenfour04