我有一个for循环,每次运行时我都会得到一个Seq[Seq[(String,Int)]]
。我有通过Seq[Seq[(String,Int)]]
运行的通常方法来获取每个Seq[(String,Int)]
,然后将其附加到ListBuffer[Seq[String,Int]]
。在循环中添加序列对象的最快方法
这里是下面的代码:
var lis; //Seq[Seq[Tuple2(String,Int)]]
var matches = new ListBuffer[(String,Int)]
someLoop.foreach(k=>
// someLoop gives lis object on evry run,
// and that needs to be added to matches list
lis.foreach(j => matches.appendAll(j))
)
是否有更好的方式,通过Seq[Seq[String,Int]]
循环做不运行这个过程中,说直接添加从Seq
所有序列对象的ListBuffer
?
我试了++
运营商,通过直接添加matches
和lis
。它也没有工作。我用Scala的2.10.2
其实'appendAll' [无异于'不同++ ='](https://github.com/scala/scala/blob/v2。 10.3/src/library/scala/collection/mutable/BufferLike.scala#L147) –
是的,你是对的。只是不要混淆“Balaram26” – serejja