Java Utililty Methods Integer Create

List of utility methods to do Integer Create

Description

The list of methods to do Integer Create are organized into topic(s).

Method

inttoInt(long l)
Converts long value to int under the conditions that the long value is representable as an int.
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE) {
    throw new IllegalArgumentException(l + " cannot be cast to int without changing its value.");
return (int) l;
inttoInt(long l)
to Int
if (l < Integer.MIN_VALUE || l > Integer.MAX_VALUE)
    throw new ArithmeticException("Value (" + l + ") cannot fit into int");
return (int) l;
inttoInt(long unsignedInt)
Converts a long containing an unsigned int value to the corresponding signed int value and returns the result as an int
if (unsignedInt < 0 || unsignedInt > MAX_INT) {
    throw new IllegalArgumentException(String.format(
            "Unsigned byte values should be in the range 0..%1$d, got: %2$d", MAX_INT, unsignedInt));
return (int) unsignedInt;
int[]toInt(long[] a)
to Int
int[] b = new int[a.length];
for (int i = 0; i < a.length; i++) {
    b[i] = (int) a[i];
return b;
inttoInt(Number num)
to Int
if (num == null) {
    return 0;
} else {
    return num.intValue();
inttoInt(Number value)
to Int
long valueLong = value.longValue();
if (valueLong < Integer.MIN_VALUE || valueLong > Integer.MAX_VALUE) {
    throw new IllegalArgumentException(valueLong + " Casting the long to an int will change its value");
return (int) valueLong;
inttoInt(Number wrapped)
to Int
if (wrapped == null) {
    return -1;
return wrapped.intValue();
inttoInt(Object bean, int defaultValue)
to Int
try {
    return (null != bean) ? Integer.parseInt(bean.toString()) : defaultValue;
} catch (Exception e) {
    e.printStackTrace();
return defaultValue;
inttoInt(Object num)
to Int
int x;
if (num instanceof Long) {
    x = ((Long) num).intValue();
} else if (num instanceof Double) {
    x = ((Double) num).intValue();
} else if (num instanceof String) {
    x = Integer.getInteger((String) num);
} else {
...
inttoInt(Object num, int defValue)
to Int
if (num != null) {
    String value = String.valueOf(num);
    try {
        return Integer.parseInt(value);
    } catch (Exception e) {
return defValue;
...