带有示例的 Scala ListSet filterNot() 方法
在 Scala ListSet 中,filterNot() 方法用于选择 listSet 中不满足指定谓词的所有元素。
Method Definition: def filterNot(p: (A) => Boolean): ListSet[A]
Return Type: It returns a new listset consisting all the elements of the listset which do not satisfy the given predicate.
示例 1:
// Scala program of filter()
// method
import scala.collection.immutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating litset
val m1 = ListSet(1, 2, 3, 4, 5, 7)
// Applying filter method
val result = m1.filterNot(_>2)
// Displays output
println(result)
}
}
输出:
ListSet(1, 2)
示例 2:
// Scala program of filter()
// method
import scala.collection.immutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating litset
val m1 = ListSet(1, 2, 3, 4, 5, 7)
// Applying filter method
val result = m1.filterNot(_<1)
// Displays output
println(result)
}
}
输出:
ListSet(1, 2, 3, 4, 5, 7)