October 2018
Intermediate to advanced
370 pages
9h 15m
English
Let's take a look at how the concepts of mutable and immutable types work in an array. The array size is immutable in any case; once the array has been declared, the size of the array cannot be updated. Sometimes, however, things get confusing when it comes to reassigning the variable. To understand this concept, let's take an example. Just like other variables, arrays can be declared with the val and var keywords:
val immutableArray = arrayOf(1,2,3)var mutableArray = arrayOf(1,2,3)
Both the immutableArray and mutableArray arrays are fixed in size, but the elements of each array are mutable and can be updated as many times as we want:
val immutableArray = arrayOf(1,2,3)immutableArray.set(0,10)immutableArray[1] ...
Read now
Unlock full access