Scala Iterator size() method with example
Last Updated :
30 Jun, 2019
The size() method belongs to the concrete value members of the class Abstract Iterator. It is defined in the classes IterableOnceOps. It is utilized to find the size of the stated collection. It will not terminate for the infinite sized collection.
Method Definition : def size: Int
Return Type :It returns the size of the stated collection..
Example #1:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator( 2.2 , 3.6 , 6.6 , 9.9 , 2.1 )
val iter 1 = iter.size
println(iter 1 )
}
}
|
Here, the length of the iterator is returned as the stated collection is non-empty.
Example #2:
object GfG
{
def main(args : Array[String])
{
val iter = Iterator()
val iter 1 = iter.size
println(iter 1 )
}
}
|
Here, the length of the iterator is zero as the stated collection is empty.
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...