Java.lang Package Classes

Java Long - sum() Method



The java.lang.Long.sum() method is used to add two long values together as per the + operator.

Syntax

public static long sum(long a,
                       long b)

Parameters

a Specify the first operand.
b Specify the second operand.

Return Value

Returns the sum of a and b.

Exception

NA.

Example:

In the example below, the java.lang.Long.sum() method is used to add two long values together as per the + operator.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating long values
    long x = 5;
    long y = 10;

    //printing the sum of long values
    System.out.println("x + y = " + Long.sum(x, y));   
  }
}

The output of the above code will be:

x + y = 15

❮ Java.lang - Long