Scala 2.13 使用什么代替 MutableList?

Scala 2.13 what to use instead of MutableList?

我正在将一个软件从 Scala 2.12.8 升级到 Scala 2.13,并发现集合 MutableList (scala.collection.mutable.MutableList) 已根据许多指南(如 this one)删除。

例如,本指南说这是一个已弃用的集合,所以这就是它被删除的原因,但我在以前的版本中找不到任何弃用 class。

"Deprecated collections were removed (MutableList, immutable.Stack, others)"

我也先升级到 2.12.9(最新版本在 2.13.0 之前)以检查是否有任何已弃用的注释给出了使用建议,但在这个版本中该集合也没有被弃用。

我搜索了这个问题,但找不到合适的答案。 这个问题对我和以后的升级都有好处。

在 Scala 2.13 中,我应该使用什么来代替 MutableList?

根据https://docs.scala-lang.org/overviews/core/collections-migration-213.html

collection.mutable.MutableList was not deprecated in 2.12 but was considered to be an implementation detail for implementing other collections. Use an ArrayDeque instead, or a List and a var.

scala> val dq = new ArrayDeque[Int]
dq: scala.collection.mutable.ArrayDeque[Int] = ArrayDeque()

scala> dq.append(1)
res1: dq.type = ArrayDeque(1)

scala> dq.append(2)
res2: dq.type = ArrayDeque(1, 2)

scala> dq
res3: scala.collection.mutable.ArrayDeque[Int] = ArrayDeque(1, 2)