VOOZH about

URL: https://www.geeksforgeeks.org/java/intstream-sum-java/

⇱ IntStream sum() in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

IntStream sum() in Java

Last Updated : 25 May, 2022

IntStream sum() returns the sum of elements in this stream. This is a special case of a reduction. IntStream sum() is a terminal operation i.e, it may traverse the stream to produce a result or a side-effect. 

Note : A reduction operation (also called a fold) takes a sequence of input elements and combines them into a single summary result by repeated application of a combining operation, such as finding the sum or maximum of a set of numbers. 

Syntax :

int sum()

Return Value : The function returns the sum of elements in this stream. 

Example 1 : 

Output:
6

Example 2 : 

Output:
18
Comment