在Scala ListSet中,filterNot()方法用於選擇listSet中不滿足指定謂詞的所有元素。
函數定義: def filterNot(p: (A) => Boolean): ListSet[A]
返回類型: 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)
相關用法
- Scala List filterNot()用法及代碼示例
- Scala Iterator filterNot()用法及代碼示例
- Scala ListSet sum()用法及代碼示例
- Scala ListSet min()用法及代碼示例
- Scala ListSet max()用法及代碼示例
- Scala ListSet find()用法及代碼示例
- Scala ListSet size()用法及代碼示例
- Scala ListSet product()用法及代碼示例
- Scala ListSet exists()用法及代碼示例
- Scala ListSet takeWhile()用法及代碼示例
- Scala ListSet count()用法及代碼示例
- Scala ListSet isEmpty()用法及代碼示例
- Scala ListSet filter()用法及代碼示例
- Scala Listset apply()用法及代碼示例
注:本文由純淨天空篩選整理自IshwarGupta大神的英文原創作品 Scala ListSet filterNot() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。