Scala Iterator nonEmpty()方法及示例
nonEmpty方法属于抽象迭代器类的具体值成员。它被用来检查所述集合是否为空。
方法定义:def nonEmpty:布尔值
返回类型。如果所述集合至少包含一个元素,则返回真,否则返回假。
例子 #1:
// Scala program of nonEmpty()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating an Iterator
val iter = Iterator(3, 4, 6)
// Applying nonEmpty method
val result = iter.nonEmpty
// Displays 输出
println(result)
}
}
输出。
true
例子#2。
// Scala program of nonEmpty()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating an empty Iterator
val iter = Iterator()
// Applying nonEmpty method
val result = iter.nonEmpty
// Displays 输出
println(result)
}
}
输出。
false
极客教程