Tag: Java 8 features
-
How to convert long to int safely in java? Math.toIntExact(long value
Math.toIntExact(long value) method, which converts a long to an int safely. This method will throw an ArithmeticException if the long value is outside of the range of int. Here’s an example code snippet that demonstrates how to use Math.toIntExact(long value): long longValue = 1234567890L;int intValue;try { intValue = Math.toIntExact(longValue);} catch (ArithmeticException e) { throw new…