The set function

The set function takes two parameters: an index of the array and a value to be assigned at that index:

intArray.set(2,3)
intArray[3] = 4
intArray.set(4,5)

Take a look at the following example:

 fun declareAndInitArray(){

var intArray = IntArray(5)
intArray[0] = 10
intArray[1] = 20
intArray.set(2,30)
intArray.set(3,40)
for (element in intArray){
println(element)
}
}

The set function takes the 2 index with a value of 30 and the 3 index with a value of 40 to initialize the array.

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

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