mutable vs. immutable in Scala collections

后端 未结 2 1725
臣服心动
臣服心动 2020-12-08 03:52

I am fairly new to Scala and am trying to understand the collections hierarchy. I see that there is a distinction between \'mutable\' and \'immutable\' collections, but I d

2条回答
  •  情话喂你
    2020-12-08 04:48

    Immutable means unchangeable. val makes a reference unchangeable, which means you cannot assign a value to a val once it has been initialized. Immutable collections make the collection itself unchangeable not the reference to it. Each time you modify an immutable collection, another collection is produced instead of modifying the original collection in-place. Most collections have both immutable and mutable versions, but there are exceptions of course.

提交回复
热议问题