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 iterator.
Here, the sum of all the elements is printed.