带有示例的 Scala TreeSet isEmpty() 方法
isEmpty()用于检查 TreeSet 是否为空。
Method Definition: def isEmpty: Boolean
Return Type: It returns true if the TreeSet is empty or else it returns false.
示例 #1:
// Scala program of isEmpty()
// method
// Import TreeSet
import scala.collection.mutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating TreeSet
val q1 = TreeSet(1, 2, 3, 4, 5)
// Print the TreeSet
println(q1)
// Applying isEmpty method
val result = q1.isEmpty
// Displays output
print("TreeSet is empty: " + result)
}
}
输出:
TreeSet(1, 2, 3, 4, 5)
TreeSet is empty: false
示例 #2:
// Scala program of isEmpty()
// method
// Import TreeSet
import scala.collection.mutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating TreeSet
val q1 = TreeSet[Int]()
// Print the TreeSet
println(q1)
// Applying isEmpty method
val result = q1.isEmpty
// Displays output
print("TreeSet is empty: " + result)
}
}
输出:
TreeSet()
TreeSet is empty: true