Srinivasan Srinivasan - 5 months ago 51
Java Question

Convert Long into Integer

How to convert a

value into an
value in Java?

Integer i = theLong != null ? theLong.intValue() : null;

or if you don't need to worry about null:

// auto-unboxing does not go from Long to int directly, so
Integer i = (int) (long) theLong;

And in both situations, you might run into overflows (because a Long can store a wider range than an Integer).