In the above example, the type of array is not mentioned. The size of this array will be fixed i.e. As the size of array is fixed, we cannot add elements to this later on. In the code above, we created an array of integers. Let us create an array of integers: val marks = arrayOf(10,9,3,4,5) We can pass the array elements as the parameter while calling the arrayOf() function. The easiest way to create an array is using arrayOf() function. We will first see how to create array using functions and later we will see how we can create using the Array class. In Kotlin the array can be created using Array class and using some Kotlin functions. Īrrays are mutable as array elements can be changed after declaration. It cannot be increased or decreased after declaration. in the same array.Īrrays are 0 index based i.e. It means, we can store integer, strings, characters, etc. In most of the languages, the array elements should be of same data type, but in Kotlin we can have array containing data of different data types. In this tutorial we will discuss about Kotlin Array.
0 Comments
Leave a Reply. |