带有示例的 Scala Iterator nonEmpty() 方法
nonEmpty方法属于抽象迭代器类的具体值成员。它用于检查声明的集合是否为空。
Method Definition: def nonEmpty: Boolean
Return Type: It returns true if the stated collection contains at least one element else returns false.
示例 #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 output
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 output
println(result)
}
}
输出:
false