Say, I have an array with values (1, 2, 3)
and another one with (4, 5, 6)
. How can I have a resultant array with values (1, 2, 3, 4, 5, 6)
?
I tried to use ++
, but that doesn't work. For example, this is what I got in the command shell.
scala> val x = Array((1, 2, 3))
x: Array[(Int, Int, Int)] = Array((1,2,3))
scala> val y = Array((4, 5, 6))
y: Array[(Int, Int, Int)] = Array((4,5,6))
scala> val z = x ++ y
z: Array[(Int, Int, Int)] = Array((1,2,3), (4,5,6))
Whereas I want Array(1, 2, 3, 4, 5, 6)
.
EDIT
I was actually using array of tuples, my bad. The Array should have been declared as Array(1, 2, 3)
and not Array((1, 2, 3))
.
val res = Array(1, 2, 3) ++ Array(4, 5, 6)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With