filter
函数的定义
def filter(p: (A) ⇒ Boolean): Seq[A]
Selects all elements of this traversable collection which satisfy a predicate.
p
the predicate used to test elements.
returns
a new traversable collection consisting of all elements of this traversable collection that satisfy the given predicate p. The order of the elements is preserved.作用
object FilterDemo1 {
def main(args: Array[String]): Unit = {
val list = List("Tom", "Aerry", "Jack").filter(startA)
println(list)
}
def startA(string: String):Boolean ={
string.startsWith("A")
}
}Last updated