Defining arrays

Kotlin provides different ways of defining an array. The simplest method is by using an arrayOf keyword with a list of comma-separated values:

val intArr = arrayOf(1,2,3,4,5)
val strArray = arrayOf("ONE","TWO","THREE","FOUR","FIVE")
val charArray = arrayOf('a','b','c','d','e')

The arrayOf function not only defines the array but also initializes it. The size of the array depends on the number of values that are assigned to it. We can check the size of the array using the size property:

val size = charArray.size
println("charArray size = " + size)

The type of array depends on the values that are assigned to it. for example  intArray, is an array of integers, while strArray is an array of strings.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.55.198