Scala SortedMap iterator method with example Last Updated : 02 Nov, 2019 Comments Improve Suggest changes Like Article Like Report 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: Scala // Scala program of iterator // method import scala.collection.immutable.SortedMap // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a SortedMap val m1 = SortedMap("geeks" -> 5, "for" -> 3, "cs" -> 2) // Applying iterator method val result = m1.iterator // Displays output println(result) } } Output: non-empty iterator Example #2: Scala // Scala program of iterator // method import scala.collection.immutable.SortedMap // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a SortedMap val m1 = SortedMap( "cs" -> 2) // Applying iterator method val result = m1.iterator // Displays output println(result) } } Output: non-empty iterator Comment More infoAdvertise with us Next Article Scala SortedMap iterator method with example G gopaldave Follow Improve Article Tags : Scala Scala Scala-Method Similar Reads Scala Mutable 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: Scala // Scala program of iterator // method import scala.collect 1 min read Scala Iterator seq() method with example The seq() method belongs to the concrete value members of the class Iterable. It is helpful in visualizing the sequential view of the stated collection. It has a time complexity of O(1). Method Definition: def seq: Iterator[A] Return Type: It returns a sequential view of the iterator. Example : Scal 1 min read Scala Iterator sum() method with example The sum() method belongs to the concrete value members of the class AbstractIterator. It is defined in the classes TraversableOnce and GenTraversableOnce. It adds the elements of the stated collection. Method Definition: def sum: A Return Type: It returns the sum of all the elements in the stated it 1 min read Scala SortedMap init() method with example The init() method is utilized to delete the last element of the SortedMap. It will return all the elements of the SortedMap except the last one. Method Definition: def init: SortedMap[A, B] Return Type: It returns all the elements of the SortedMap except the last one. Example #1: Scala // Scala prog 1 min read Scala Iterator take() method with example The take() method belongs to the concrete value member of the class Abstract Iterator. It is utilized to select the first n elements of the stated iterator. Method Definition: def take(n: Int): Iterator[A] Where, n is the number of element to take from the given iterator. Return Type: It returns the 2 min read Like