VOOZH about

URL: https://www.geeksforgeeks.org/java/java-guava-longmath-checkedaddlong-a-long-b-method-with-examples/

⇱ Java Guava | LongMath.checkedAdd(long a, long b) method with Examples - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Java Guava | LongMath.checkedAdd(long a, long b) method with Examples

Last Updated : 11 Jul, 2025
The checkedAdd(long a, long b) is a method of Guava's LongMath Class which accepts two parameters a and b, and returns their sum. Syntax:
public static long checkedAdd(long a, long b)
Parameters: The method accepts two long values a and b and computes their sum. Return Value: The method returns the sum of long values passed to it, provided it does not overflow. Exceptions: The method checkedAdd(long a, long b) throws ArithmeticException if the sum i.e, (a - b) overflows in signed long arithmetic. Below examples illustrate the implementation of above method: Example 1:
Output:
Sum of 25 and 36 is: 61
Sum of 150 and 667 is: 817
Example 2:
Comment