问题
According to the docs, scala.collection.mutable.LinkedList is deprecated as of the 2.11 version. Unfortunately I have found nothing to replace it with. I need an ordered collection that can remove an item from any index in constant time.
What should I use?
回答1:
Use MutableList and its iterator's remove method. They provide O(1) removal.
http://docs.scala-lang.org/overviews/collections/concrete-mutable-collection-classes.html#linked_lists
回答2:
From what I understand of your problem you want to iterate through collection and change it on the fly. That is not possible with collection constructs other than (now deprecated) scala.collection.mutable.LinkedList or scala.collection.mutable.DoubleLinkedList. This kind of operation doesn't really follow the Scala collections philosophy hence LinkedList and DoubleLinkedList are deprecated now.
However nothing stops you from using classic Java's java.util.LinkedList and relevant iterator in your Scala code.
Unless you want to review your design and follow Scala's way using constructs like: map, filter, for, fold, reduce, etc. For example, using filter function you can create a new list with only relevant items.
来源:https://stackoverflow.com/questions/27557427/scala-2-11-linkedlist-is-deprecated-what-should-i-use