Scala SortedSet isEmpty()方法及示例
isEmpty() 方法是用来测试排序集是否为空的。
方法定义: def isEmpty:Boolean
返回类型。如果排序集是空的,返回真,否则返回假。
例子 #1:
// Scala program of isEmpty()
// method
import scala.collection.immutable.SortedSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a SortedSet
val s1 = SortedSet(1, 2, 3, 4, 5)
// Applying isEmpty method
val result = s1.isEmpty
// Display output
println(result)
}
}
输出。
false
例子#2。
// Scala program of isEmpty()
// method
import scala.collection.immutable.SortedSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a SortedSet
val s1 = SortedSet()
// Applying isEmpty method
val result = s1.isEmpty
// Display output
println(result)
}
}
输出。
true
极客教程