Integer sum() Method in Java (original) (raw)

Last Updated : 21 Jan, 2026

The Integer.sum() method in Java is a static utility method provided by the java.lang.Integer class. It is used to return the sum of two integer values, behaving exactly like the + operator but offering better readability and usability in functional-style programming.

**Example 1: This program demonstrates how to use the Integer.sum() method to add two integer values in Java.

Java `

class GFG { public static void main(String[] args) { int a = 62; int b = 18; System.out.println("The sum is = " + Integer.sum(a, b)); } }

`

**Explanation:

Syntax

public static int sum(_int a, int b)

**Parameter:

**Return Value: Returns an int value which is the sum of the two arguments.

How It Works

**Example 2: Integer Overflow / Invalid Large Value

Java `

class GFG { public static void main(String[] args) { int a = 92374612162; int b = 181; System.out.println(Integer.sum(a, b)); } }

`

**Output:

error: integer number too large

**Explanation:

**Example 3: Finding Sum of Integers Using a Loop

java `

class GFG { public static void main(String[] args) { int[] arr = { 2, 4, 6, 8, 10 }; int sum = 0;

    for (int i = 0; i < arr.length; i++) {
        sum = Integer.sum(sum, arr[i]);
    }
    System.out.println("Sum of array elements is: " + sum);
}

}

`