No Scala mutable list

Scala has both a mutable and an immutable Map , but it has only an immutable List. If you want a mutable List you need a ListBuffer.

I don't understand why this is so. Any one knows?.

Answers


You can choose between these:

So, yes, Scala has mutable lists :-)


I hope that this article may be of some use to you. The diagram at the bottom of the page is particularly useful in providing the mutable and immutable classes.

http://www.scala-lang.org/docu/files/collections-api/collections_1.html


There is a mutable List, but it is called Buffer. The article linked by Graham goes into more depth, but I thought there should be a specific answer to the question as well.


Map is a trait -- like Java's interface --, while List is a class, a concrete implementation of a Seq. There are mutable and immutable Seq, just like for Map.

This may be confusing to Java programmers because, in Java, List is an interface, whose (main) implementations are ArrayList and LinkedList. Alas, Java naming is atrocious. First, ArrayList is not a List by any stretch of imagination. Also, the interface has methods that are not really related to any traditional list.

So, if you want mutable/immutable equivalence, look to concrete subclass implementations of Seq.


Need Your Help

How to listen contact inserted/updated/deleted in address book

android sync android-contacts contentobserver

There are lots of questions related to it but none of them help me to get the solution.