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

StringtoIntString(Object object)
to Int String
if (object == null) {
    return null;
} else if (object instanceof Number) {
    return String.valueOf(((Number) object).intValue());
} else {
    return object.toString();
inttoIntUnsigned(short x)
to Int Unsigned
return x & 0xFFFF;
inttoIntValue(char ch)
to Int Value
if (!isDigit(ch)) {
    throw new IllegalArgumentException("The character " + ch + " is not in the range '0' - '9'");
return ch - 48;
inttoIntValue(char ch, int defaultValue)

Converts the character to the Integer it represents, throwing an exception if the character is not numeric.

This method coverts the char '1' to the int 1 and so on.

 CharUtils.toIntValue('3', -1)  = 3 CharUtils.toIntValue('A', -1)  = -1 
if (isNumeric(ch) == false)
    return defaultValue;
return ch - 48;
inttoIntValue(final char ch)

Converts the character to the Integer it represents, throwing an exception if the character is not numeric.

This method converts the char '1' to the int 1 and so on.

 CharUtils.toIntValue('3')  = 3 CharUtils.toIntValue('A')  throws IllegalArgumentException 
if (!isAsciiNumeric(ch)) {
    throw new IllegalArgumentException("The character " + ch + " is not in the range '0' - '9'");
return ch - 48;
inttoIntValue(final Object o)
to Int Value
if (o instanceof Integer)
    return ((Integer) o).intValue();
return 0;
inttoIntValue(Object number)
Returns the number object as an int
if (number == null) {
    return 0;
if (number instanceof Integer) {
    return ((Integer) number).intValue();
if (number instanceof String) {
    String n = (String) number;
...
StringtoIntValueString(byte[] ip)
to Int Value String
int v1 = ip[3] & 0xFF;
int v2 = (ip[2] << 8) & 0xFF00;
int v3 = (ip[1] << 16) & 0xFF0000;
int v4 = (ip[0] << 24);
long ipValue = ((long) (v4 | v3 | v2 | v1)) & 0x00000000FFFFFFFFl;
return String.valueOf(ipValue);
inttoIntWithoutOverflow(float value)
Like Math#toIntExact(long) but for int range.
if (value < Integer.MIN_VALUE || value > Integer.MAX_VALUE) {
    throw new ArithmeticException("int overflow");
return (int) value;
inttoIntWithPrefix(byte prefix, byte[] bytes)
to Int With Prefix
assert (bytes[0] == prefix);
assert (bytes.length >= 5);
return (int) ((0xff & bytes[1]) << 24 | (0xff & bytes[2]) << 16 | (0xff & bytes[3]) << 8
        | (0xff & bytes[4]) << 0);