contains()方法用於檢查是否在not的SortedSet中存在元素。
函數定義: def contains(elem: A): Boolean
返回類型: It returns true if the element is present in the SortedSet else it returns false.
範例1:
// Scala program of contains()
// method
import scala.collection.immutable.SortedSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a SortedSet
val s1 = SortedSet(41, 12, 23, 43, 1, 72)
// Applying contains() method
val result = s1.contains(1)
// Display output
print(result)
}
}
輸出:
true
範例2:
// Scala program of contains()
// method
import scala.collection.immutable.SortedSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a SortedSet
val s1 = SortedSet(41, 12, 23, 43, 1, 72)
// Applying contains() method
val result = s1.contains(10)
// Display output
print(result)
}
}
輸出:
false
相關用法
- Scala SortedSet min()用法及代碼示例
- Scala SortedSet sum()用法及代碼示例
- Scala SortedSet take()用法及代碼示例
- Scala SortedSet +()用法及代碼示例
- Scala SortedSet -()用法及代碼示例
- Scala SortedSet &()用法及代碼示例
- Scala SortedSet &~()用法及代碼示例
- Scala SortedSet max()用法及代碼示例
- Scala SortedSet map()用法及代碼示例
- Scala SortedSet ++()用法及代碼示例
- Scala SortedSet last()用法及代碼示例
- Scala SortedSet dropWhile()用法及代碼示例
- Scala SortedSet exists()用法及代碼示例
- Scala SortedSet toList()用法及代碼示例
- Scala SortedSet toMap()用法及代碼示例
注:本文由純淨天空篩選整理自gopaldave大神的英文原創作品 Scala SortedSet contains() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。