Replace element in List with scala

后端 未结 7 1110
花落未央
花落未央 2021-02-01 00:45

How do you replace an element by index with an immutable List.

E.g.

val list = 1 :: 2 ::3 :: 4 :: List()

list.replace(2, 5)
7条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-01 01:24

    If you do a lot of such replacements, it is better to use a muttable class or Array.

提交回复
热议问题