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 first n values from the stated iterator, or the whole iterator, whichever is shorter.
2 3 5 7
Here, first four elements are displayed as we have selected first four elements in the method.
2 3 5 7 8 9
Here, the whole iterator is displayed as the number of elements in that is shorter than the number of elements selected by the method. so, the shorter one is displayed.