Scala: the best way to iterate over a collection and populate an array

scala noob here, I have a collection (Seq) of xml nodes, and I would like to populate an array based on each node:

val nodes = data.child \\"package"
var packages = new Array[Package](nodes.length)
var index = 0
for(val entry <- nodes) {
   packages(index) = new Package(entry)
   index = index+1
}

Despite the fact that it works, it does not look like "w61> -ish", and I'm sure there is a better way to do this.
Any ideas?

+5
source share
1 answer
(data.child \\ "package") map(new Package(_)) toArray
+12
source

All Articles