ncelik ncelik - 1 month ago 7
Scala Question

Array operations that changes the order of element in scala

In scala documentation it states that Lists are immutable and "you can rely on the fact that accessing the same collection value repeatedly at different points in time will always yield a collection with the same elements" On the other hand in arrays (mutable) some operations can change the element. Can you give me some array examples for those operations that changes element by comparing with example on lists?

Answer
val arr = Array(3,5,7)
arr(1) = 0  // arr is now Array(3,0,7)

val lst = List(3,5,7)
lst(1) = 0  // error: value update is not a member of List[Int]