scala ListBuffer 列表取循环取数据

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)
posted @ 2023-07-31 16:54  iullor  阅读(38)  评论(0编辑  收藏  举报