score:1

Accepted answer

For arrays you can use the reverse:

myiterable.copyToArray(myarray)

score:-1

Simply use myIterable.toArray()

score:0

If myarray is indeed an array, you have the IterableLike.copyToArray family of functions.


If you're using a mutable collection, you can use append. From the documentation:

scala> val a = LinkedList(1, 2)
a: scala.collection.mutable.LinkedList[Int] = LinkedList(1, 2)

scala> val b = LinkedList(1, 2)
b: scala.collection.mutable.LinkedList[Int] = LinkedList(1, 2)

scala> a.append(b)
res0: scala.collection.mutable.LinkedList[Int] = LinkedList(1, 2, 1, 2)

scala> println(a)
LinkedList(1, 2, 1, 2)

If you're using an immutable collection, then you cannot append anything to it.


Related Query

More Query from same tag