Scala Iterator length() method with example
The length() method belongs to the concrete value members of the class AbstractIterator. It is defined in the class Iterator. It is also identical to the method size, it is also utilized to find the length of the stated collection.
Method Definition : final def length: Int
Return Type :It returns the length of the stated collection.
Example #1:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 2 , 3 , 5 , 7 , 11 )
val iter 1 = iter.length
println(iter 1 )
}
}
|
Here, the stated iterator is non-empty so, the length of the given collection is returned.
Example #2:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator()
val iter 1 = iter.length
println(iter 1 )
}
}
|
Here, the stated iterator is empty so, the length of the given collection is zero.
Last Updated :
30 Jun, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...