Scala: what is the best way to append an element to an Array?

后端 未结 3 1735
你的背包
你的背包 2021-01-29 21:34

Say I have an Array[Int] like

val array = Array( 1, 2, 3 )

Now I would like to append an element to the array, say the value

3条回答
  •  庸人自扰
    2021-01-29 21:59

    The easiest might be:

    Array(1, 2, 3) :+ 4
    

    Actually, Array can be implcitly transformed in a WrappedArray

提交回复
热议问题