Scala Iterator nonEmpty() method with example
Last Updated :
13 Aug, 2019
The nonEmpty method belongs to the concrete value member of the class Abstract Iterator. It is utilized to check whether the stated collection is not empty.
Method Definition: def nonEmpty: Boolean
Return Type: It returns true if the stated collection contains at least one element else returns false.
Example #1:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 3 , 4 , 6 )
val result = iter.nonEmpty
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator()
val result = iter.nonEmpty
println(result)
}
}
|
Share your thoughts in the comments
Please Login to comment...