Scala Map isEmpty() 方法与示例
isEmpty()方法用于检查给定的地图是否为空。
Method Definition: def isEmpty: Boolean
Return Type: It returns true if the stated map is empty else returns false.
示例 #1:
// Scala program of isEmpty()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating map
val m1 = Map(3 -> "geeks", 1 -> "for", 2 -> "cs", 3 -> "geeks")
// Applying isEmpty method
val result = m1.isEmpty
// Displays output
println(result)
}
}
输出:
false
示例 #2:
// Scala program of isEmpty()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating map
val m1 = Map()
// Applying isEmpty method
val result = m1.isEmpty
// Displays output
println(result)
}
}
输出:
true