Scala SortedMap iterator method with example
The iterator method is utilized to give an iterator.
Method Definition: def iterator: Iterator[(A, B)]
Return Type: It returns a non-empty iterator for non-empty SortedMap and returns an empty iterator for empty SortedMap.
Example #1:
import scala.collection.immutable.SortedMap
object GfG
{
def main(args : Array[String])
{
val m 1 = SortedMap( "geeks" - > 5 , "for" - > 3 , "cs" - > 2 )
val result = m 1 .iterator
println(result)
}
}
|
Output:
non-empty iterator
Example #2:
import scala.collection.immutable.SortedMap
object GfG
{
def main(args : Array[String])
{
val m 1 = SortedMap( "cs" - > 2 )
val result = m 1 .iterator
println(result)
}
}
|
Output:
non-empty iterator
Last Updated :
02 Nov, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...