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