The function where an array index is acceptable to return the initial value of the index.
For Example:
val abc = Array(7 , { i -> i*1})
Here, the value of array is 7 and lambda expression is used to initialize the values of the element.
There are also various methods to access and modify the arrays using certain functions. Therefore, there are two member functions get() and set(), which are used to access class array’s objects.
For Example:
val x = arrayOf(10,20,30,40,50,60,70,80,90)
val y = x.get(0) // Output 10
Here, the output is 10 since the value at the index 0 of array is 10
Note : get() takes only single values
For Example:
val x = arrayOf(10,20,30,40,50,60,70.80.90)
val y = x.set(2, 3) //
Output : 30 40
Here, the output is 30 and 40 since the value at the index 2 of array is 30 and at index 3 it is 40.
Note: set() takes multiple values of an array.