scala ListBuffer 列表取循环取数据
object Test {
def main(args: Array[String]): Unit = {
var list = scala.collection.mutable.ListBuffer(1, 2, 3, 4, 5, 6, 7)
/*list.foreach(item => {
println(s"当前list:$list")
list = list.drop(2)
})*/
val batchSize = 2
val times = (list.size / batchSize) + 1
for (i <- 1 to times) {
println(list.take(batchSize))
list = list.drop(batchSize)
}
}
}
运行结果
ListBuffer(1, 2)
ListBuffer(3, 4)
ListBuffer(5, 6)
ListBuffer(7)
标签:val,scala,batchSize,list,列表,ListBuffer
From: https://www.cnblogs.com/iullor/p/17593890.html