Scala Iterator size() method with example Last Updated : 30 Jun, 2019 Comments Improve Suggest changes Like Article Like Report 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: Scala // Scala program of size() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Declaring an iterator val iter = Iterator(2.2, 3.6, 6.6, 9.9, 2.1) // Applying size method val iter1 = iter.size // Displays output println(iter1) } } Output: 5 Here, the length of the iterator is returned as the stated collection is non-empty. Example #2: Scala // Scala program of size() // method // Creating object object GfG { // Main method def main(args:Array[String]) { // Declaring an empty-iterator val iter = Iterator() // Applying size method val iter1 = iter.size // Displays output println(iter1) } } Output: 0 Here, the length of the iterator is zero as the stated collection is empty. Comment More infoAdvertise with us Next Article Scala Iterator size() method with example N nidhi1352singh Follow Improve Article Tags : Scala Scala Scala-Method Similar Reads 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 slice() method with example The slice() method belongs to the concrete value members of the class AbstractIterator. It is defined in the class Iterator. It creates a new iterator for the interval given in the slice. The first value present in the slice indicates the start of the element in the new iterator and the second value 2 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 Iterator toSeq() method with example The toSeq() method belongs to the concrete value member of the class Abstract Iterator. It is equivalent to the Seq method but this method is more faster. Method Definition: val result = iter.toSeq Return Type: It returns the stated collection as a sequence. Example #1: Scala // Scala program of toS 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