scala 删除元素
The list is an immutable data structure so deleting elements is note easily possible. One way to do this is to filter out elements using filtering methods like filter, partition, splitAt, take, etc.
该列表是不可变的数据结构,因此删除元素很容易实现。 一种方法是使用filter , partition , splitAt , take等过滤方法过滤掉元素。
Program:
程序:
object MyClass {
def main(args: Array[String]) {
var progLang = List("C++", "Java", "Scala", "Python")
println("Programming Languages: " + progLang)
var newLang = progLang.filter(_<"P")
println("Programming Languages: " + newLang)
}
}
Output
输出量
Programming Languages: List(C++, Java, Scala, Python)
Programming Languages: List(C++, Java)
Other methods to modify the list are using ListBuffer which is mutable that makes the deletion process easy.
修改列表的其他方法是使用ListBuffer ,它是可变的,使