'Kotlin fixed array of strings [duplicate]

is it possible to create fixed size array of strings using Kotlin like in Java ?

something like val arrayOfString: Array(5)



Solution 1:[1]

Sort of.

In Kotlin, you can't have val arrayOfString : Array<String> = Array(5), because the values filling the array would be null, and null isn't a valid value of String.

You can have val arrayOfString: Array<String?> = arrayOfNulls(5), or you can have val arrayOfString : Array<String> = Array(5) { "defaultString" }.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Louis Wasserman