如何更换不可改变的数组中的值 scala

我有一个数组


val doot = Array/"a", "b", "c"/


我想替换第二个索引字母 "z", 但我不想改变 doot. 我想创建一个新的数组,因为它似乎是成语 scala.

到目前为止,我只能通过更新来更改数组


doot.update/1, "z"/ // But now doot is modified directly, not ideal!


提供谎言 scala 这样做?
已邀请:

帅驴

赞同来自:

scala> val doot = Array/"a", "b", "c"/
doot: Array[String] = Array/a, b, c/

scala> val eoot = doot.updated/1, "z"/
eoot: Array[String] = Array/a, z, c/

scala> doot
res0: Array[String] = Array/a, b, c/

scala> eoot
res1: Array[String] = Array/a, z, c/

要回复问题请先登录注册