flatMap切割后用map将String类型转化为int类型

def main(args: Array[String]): Unit = {
      var arr = mutable.ArrayBuffer[String]()
      arr.append("10,23,44")
      arr.append("45,88,55")
      arr.append("22,1000,43")
      arr.append("22,4,1")

  val a1 = arr.flatMap(_.split(","))
  val a2 = a1.map(x => x.toInt)
  a2.foreach(println(_))

  println("----------累加---------")
  val a3 = a2.reduce(_ + _)
  println("累加结果为:" + a3)
}

你可能感兴趣的:(flatMap切割后用map将String类型转化为int类型)