Scala:迭代集合和填充数组的最佳方法
scala noob在这里,我有一个xml节点的集合(Seq),我想根据每个节点填充一个数组:
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
}
虽然它有效,但对我来说看起来不太“scala-ish”,而且我'我确信有更好的方法来做到这一点..
有什么想法吗?
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
}
Although it works, does not look much "scala-ish" to me, and i'm sure there's a better way to do it..
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)