![]() ![]() We can access an array element by using the index number inside square brackets. Other factory methods available for creating arrays: For example, the factory method to create an integer array is: Kotlin also has some built-in factory methods to create arrays of primitive data types. Optionally we can provide a data type as follows:Īlternatively, the arrayOfNulls() function can be used to create an array of a given size filled with null elements. Val fruits = arrayOf("Apple", "Mango", "Banana", "Orange") To create an array in Kotlin, we use the arrayOf() function, and place the values in a comma-separated list inside it: ![]() Like any other modern programming languages, Kotlin also supports arrays and provide a wide range of array properties and support functions to manipulate arrays. Arrays are used to store multiple items of the same data-type in a single variable, such as an integer or string under a single variable name.įor example, if we need to store names of 1000 employees, then instead of creating 1000 different string variables, we can simply define an array of string whose capacity will be 1000. ![]()
0 Comments
Leave a Reply. |