Scala 2.11 LinkedList is deprecated, what should I use?

风流意气都作罢 提交于 2019-12-03 10:44:52

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!