是否有任何可变集合的运算符方法可以将结果写回可变运算符调用程序或参数?

Is there any operator method of mutable collections that can write the result back to the mutable operator invoker or argument?

::, ::: List 的运算符方法 return 一个新的 List.
+ SetMap 的运算符方法 return 一个新的 SetMap,依此类推。
集合的所有运算符方法 return 是否为新集合?
是否有任何异常的可变集合运算符方法可以将结果写回可变运算符调用程序或参数?
这样我就不需要将结果重新分配给可变调用程序或参数。

+= 应该有效

例子来自网络

import scala.collection.mutable.ArrayBuffer
import scala.collection.mutable.Map

val fruits = ArrayBuffer[String]()
fruits += "Apple"
fruits += "Banana"
fruits += "Orange"

val x = Map("AL" -> "Alabama")
x += ("AK" -> "Alaska")

Do all operator methods of collections return a new collection?

在功能世界中是的,因为一切都是 不可变的

由于 Scala 也支持 imperativ 风格,因此 mutable 集合上有运算符。 请参阅 Dimitry 的 回答中的示例。