Scala Map isEmpty() 方法及其例子
isEmpty() 方法用来检查给定的 map 是否为空。
方法定义:def isEmpty: Boolean
返回类型:如果给定的 map 为空,则返回 true,否则返回 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
阅读更多:Scala 教程
极客教程