val lst = List(1, 2, 3, 4, 5, 6, 7, 8, 9) val a = (List[Int]() /: lst) ((i, l) => l +: i) val b = lst.foldLeft(List[Int]())((i, l) => l +: i) val c = lst.foldLeft(List[Int]())((i, l) => i :+ l) println(a) //List(9, 8, 7, 6, 5, 4, 3, 2, 1) println(b) //List(9, 8, 7, 6, 5, 4, 3, 2, 1) println(c) //List(1, 2, 3, 4, 5, 6, 7, 8, 9)
list的:+ 和 :+操作区别
最新推荐文章于 2021-01-24 17:09:20 发布