Java : Integer with Examples
Integer (Java SE 18 & JDK 18) API Examples.
You will find code examples on most Integer methods.
Summary
// Compile error.
final var list = new ArrayList<int>();
// OK.
final var list = new ArrayList<Integer>();
list.add(1);
list.add(2);
list.add(3);
System.out.println(list); // [1, 2, 3]
Fields
static final int BYTES
System.out.println(Integer.BYTES); // 4
static final int MAX_VALUE
System.out.println(Integer.MAX_VALUE); // 2147483647
System.out.println("0x" + Integer.toHexString(Integer.MAX_VALUE)); // "0x7fffffff"
static final int MIN_VALUE
System.out.println(Integer.MIN_VALUE); // -2147483648
System.out.println("0x" + Integer.toHexString(Integer.MIN_VALUE)); // "0x80000000"
static final int SIZE
System.out.println(Integer.SIZE); // 32
static final Class<Integer> TYPE
System.out.println(Integer.TYPE.getSimpleName()); // "int"
System.out.println(Integer.TYPE.isPrimitive()); // true
Constructors
Integer (int value)
Deprecated.
Integer (String s)
Deprecated.
Methods
static int bitCount (int i)
int value = 0;
System.out.println(Integer.toBinaryString(value)); // "0"
System.out.println(Integer.bitCount(value)); // 0
int value = 1;
System.out.println(Integer.toBinaryString(value)); // "1"
System.out.println(Integer.bitCount(value)); // 1
int value = 2;
System.out.println(Integer.toBinaryString(value)); // "10"
System.out.println(Integer.bitCount(value)); // 1
int value = 3;
System.out.println(Integer.toBinaryString(value)); // "11"
System.out.println(Integer.bitCount(value)); // 2
int value = 4;
System.out.println(Integer.toBinaryString(value)); // "100"
System.out.println(Integer.bitCount(value)); // 1
int value = 5;
System.out.println(Integer.toBinaryString(value)); // "101"
System.out.println(Integer.bitCount(value)); // 2
int value = 6;
System.out.println(Integer.toBinaryString(value)); // "110"
System.out.println(Integer.bitCount(value)); // 2
int value = 7;
System.out.println(Integer.toBinaryString(value)); // "111"
System.out.println(Integer.bitCount(value)); // 3
int value = Integer.MAX_VALUE;
System.out.println(Integer.toBinaryString(value)); // "1111111111111111111111111111111"
System.out.println(Integer.bitCount(value)); // 31
int value = Integer.MIN_VALUE;
System.out.println(Integer.toBinaryString(value)); // "10000000000000000000000000000000"
System.out.println(Integer.bitCount(value)); // 1
byte byteValue ()
final var ret1 = Integer.valueOf(0).byteValue();
System.out.println(ret1); // 0
final var ret2 = Integer.valueOf(123).byteValue();
System.out.println(ret2); // 123
final var ret3 = Integer.valueOf(-45).byteValue();
System.out.println(ret3); // -45
final var ret1 = Integer.valueOf(Byte.MAX_VALUE).byteValue();
System.out.println(ret1); // 127
final var ret2 = Integer.valueOf(Byte.MIN_VALUE).byteValue();
System.out.println(ret2); // -128
final var ret1 = Integer.valueOf(127).byteValue();
System.out.println(ret1); // 127
final var ret3 = Integer.valueOf(128).byteValue();
System.out.println(ret3); // -128
final var ret4 = Integer.valueOf(129).byteValue();
System.out.println(ret4); // -127
final var ret1 = Integer.valueOf(-128).byteValue();
System.out.println(ret1); // -128
final var ret3 = Integer.valueOf(-129).byteValue();
System.out.println(ret3); // 127
final var ret4 = Integer.valueOf(-130).byteValue();
System.out.println(ret4); // 126
static int compare (int x, int y)
System.out.println(Integer.compare(0, 0)); // 0
System.out.println(Integer.compare(0, 1)); // -1
System.out.println(Integer.compare(1, 0)); // 1
System.out.println(Integer.compare(1, -2)); // 1
System.out.println(Integer.compare(-4, -2)); // -1
System.out.println(Integer.compare(1000, -1000)); // 1
int compareTo (Integer anotherInteger)
final var value1 = Integer.valueOf(0);
final var value2 = Integer.valueOf(0);
System.out.println(value1.compareTo(value2)); // 0
final var value1 = Integer.valueOf(0);
final var value2 = Integer.valueOf(1);
System.out.println(value1.compareTo(value2)); // -1
final var value1 = Integer.valueOf(1);
final var value2 = Integer.valueOf(0);
System.out.println(value1.compareTo(value2)); // 1
final var value1 = Integer.valueOf(1);
final var value2 = Integer.valueOf(-2);
System.out.println(value1.compareTo(value2)); // 1
final var value1 = Integer.valueOf(-4);
final var value2 = Integer.valueOf(-2);
System.out.println(value1.compareTo(value2)); // -1
final var value1 = Integer.valueOf(Integer.MAX_VALUE);
final var value2 = Integer.valueOf(Integer.MIN_VALUE);
System.out.println(value1.compareTo(value2)); // 1
static int compareUnsigned (int x, int y)
final int value1 = 0;
final int value2 = 0;
System.out.println("0x" + Integer.toHexString(value1)); // "0x0"
System.out.println("0x" + Integer.toHexString(value2)); // "0x0"
System.out.println(Integer.compareUnsigned(value1, value2)); // 0
final int value1 = -1;
final int value2 = 1;
System.out.println("0x" + Integer.toHexString(value1)); // "0xffffffff"
System.out.println("0x" + Integer.toHexString(value2)); // "0x1"
System.out.println(Integer.compareUnsigned(value1, value2)); // 1
final int value1 = -1;
final int value2 = -2;
System.out.println("0x" + Integer.toHexString(value1)); // "0xffffffff"
System.out.println("0x" + Integer.toHexString(value2)); // "0xfffffffe"
System.out.println(Integer.compareUnsigned(value1, value2)); // 1
final int value1 = 5;
final int value2 = 10;
System.out.println("0x" + Integer.toHexString(value1)); // "0x5"
System.out.println("0x" + Integer.toHexString(value2)); // "0xa"
System.out.println(Integer.compareUnsigned(value1, value2)); // -1
final int value1 = Integer.MAX_VALUE;
final int value2 = Integer.MIN_VALUE;
System.out.println("0x" + Integer.toHexString(value1)); // "0x7fffffff"
System.out.println("0x" + Integer.toHexString(value2)); // "0x80000000"
System.out.println(Integer.compareUnsigned(value1, value2)); // -1
static Integer decode (String nm)
System.out.println(Integer.decode("0")); // 0
System.out.println(Integer.decode("123")); // 123
System.out.println(Integer.decode("+456")); // 456
System.out.println(Integer.decode("-789")); // -789
//Integer.decode("xyz"); // NumberFormatException
// Hexadecimal
final var ret1 = Integer.decode("0xff");
System.out.println(ret1); // 255
System.out.println(Integer.toHexString(ret1)); // "ff"
final var ret2 = Integer.decode("-0xff");
System.out.println(ret2); // -255
System.out.println(Integer.toHexString(ret2)); // "ffffff01"
final var ret3 = Integer.decode("#abcd");
System.out.println(ret3); // 43981
System.out.println(Integer.toHexString(ret3)); // "abcd"
final var ret4 = Integer.decode("0X7fffffff");
System.out.println(ret4); // 2147483647
System.out.println(Integer.toHexString(ret4)); // "7fffffff"
// Octal
final var ret1 = Integer.decode("01234");
System.out.println(ret1); // 668
System.out.println(Integer.toOctalString(ret1)); // "1234"
final var ret2 = Integer.decode("-01234");
System.out.println(ret2); // -668
System.out.println(Integer.toOctalString(ret2)); // "37777776544"
Optional<Integer> describeConstable ()
final var ret = Integer.valueOf(123).describeConstable();
System.out.println(ret); // Optional[123]
static int divideUnsigned (int dividend, int divisor)
final var value = -1294967296;
System.out.println(value / 2); // -647483648
System.out.println(Integer.toUnsignedString(value)); // 3000000000
System.out.println(Integer.divideUnsigned(value, 2)); // 1500000000
double doubleValue ()
final var value = Integer.valueOf(1234).doubleValue();
System.out.println(value); // 1234.0
final var value = Integer.valueOf(-4567).doubleValue();
System.out.println(value); // -4567.0
final var value = Integer.valueOf(Integer.MAX_VALUE).doubleValue();
System.out.println(value); // 2.147483647E9
final var value = Integer.valueOf(Integer.MIN_VALUE).doubleValue();
System.out.println(value); // -2.147483648E9
boolean equals (Object obj)
final var value1 = Integer.valueOf(100);
final var value2 = Integer.valueOf(100);
final var value3 = Integer.valueOf(999);
System.out.println(value1.equals(100)); // true
System.out.println(value1.equals(value2)); // true
System.out.println(value1.equals(value3)); // false
final var value1 = Integer.valueOf(100);
final var value2 = Long.valueOf(100);
System.out.println(value1.equals(value2)); // false
float floatValue ()
final var value = Integer.valueOf(1234).floatValue();
System.out.println(value); // 1234.0
final var value = Integer.valueOf(-4567).floatValue();
System.out.println(value); // -4567.0
final var value = Integer.valueOf(Integer.MAX_VALUE).floatValue();
System.out.println(value); // 2.14748365E9
final var value = Integer.valueOf(Integer.MIN_VALUE).floatValue();
System.out.println(value); // -2.14748365E9
static Integer getInteger (String nm)
final var key = "java.specification.version";
System.out.println(Integer.getInteger(key)); // 17
System.out.println(System.getProperty(key)); // "17"
final var key = "os.name";
System.out.println(Integer.getInteger(key)); // null
System.out.println(System.getProperty(key)); // "Windows 10"
static Integer getInteger (String nm, int val)
final var key = "java.specification.version";
System.out.println(Integer.getInteger(key, 999)); // 17
System.out.println(System.getProperty(key)); // "17"
final var key = "os.name";
System.out.println(Integer.getInteger(key)); // null
System.out.println(Integer.getInteger(key, 999)); // 999
System.out.println(System.getProperty(key)); // "Windows 10"
static Integer getInteger (String nm, Integer val)
final var key = "java.specification.version";
System.out.println(Integer.getInteger(key, Integer.valueOf(999))); // 17
System.out.println(System.getProperty(key)); // "17"
final var key = "os.name";
System.out.println(Integer.getInteger(key)); // null
System.out.println(Integer.getInteger(key, Integer.valueOf(999))); // 999
System.out.println(System.getProperty(key)); // "Windows 10"
int hashCode ()
System.out.println(Integer.valueOf(0).hashCode()); // 0
System.out.println(Integer.valueOf(1).hashCode()); // 1
System.out.println(Integer.valueOf(2).hashCode()); // 2
System.out.println(Integer.valueOf(3456).hashCode()); // 3456
System.out.println(Integer.valueOf(-7890).hashCode()); // -7890
System.out.println(Integer.valueOf(Integer.MAX_VALUE).hashCode()); // 2147483647
System.out.println(Integer.valueOf(Integer.MIN_VALUE).hashCode()); // -2147483648
static int hashCode (int value)
System.out.println(Integer.hashCode(0)); // 0
System.out.println(Integer.hashCode(1)); // 1
System.out.println(Integer.hashCode(2)); // 2
System.out.println(Integer.hashCode(3456)); // 3456
System.out.println(Integer.hashCode(-7890)); // -7890
System.out.println(Integer.hashCode(Integer.MAX_VALUE)); // 2147483647
System.out.println(Integer.hashCode(Integer.MIN_VALUE)); // -2147483648
static int highestOneBit (int i)
final var value = 0;
System.out.println(Integer.toBinaryString(value)); // "0"
final var ret = Integer.highestOneBit(value);
System.out.println(ret); // 0
System.out.println(Integer.toBinaryString(ret)); // "0"
final var value = 1;
System.out.println(Integer.toBinaryString(value)); // "1"
final var ret = Integer.highestOneBit(value);
System.out.println(ret); // 1
System.out.println(Integer.toBinaryString(ret)); // "1"
final var value = 2;
System.out.println(Integer.toBinaryString(value)); // "10"
final var ret = Integer.highestOneBit(value);
System.out.println(ret); // 2
System.out.println(Integer.toBinaryString(ret)); // "10"
final var value = 3;
System.out.println(Integer.toBinaryString(value)); // "11"
final var ret = Integer.highestOneBit(value);
System.out.println(ret); // 2
System.out.println(Integer.toBinaryString(ret)); // "10"
final var value = 4;
System.out.println(Integer.toBinaryString(value)); // "100"
final var ret = Integer.highestOneBit(value);
System.out.println(ret); // 4
System.out.println(Integer.toBinaryString(ret)); // "100"
final var value = 5;
System.out.println(Integer.toBinaryString(value)); // "101"
final var ret = Integer.highestOneBit(value);
System.out.println(ret); // 4
System.out.println(Integer.toBinaryString(ret)); // "100"
final var value = 6;
System.out.println(Integer.toBinaryString(value)); // "110"
final var ret = Integer.highestOneBit(value);
System.out.println(ret); // 4
System.out.println(Integer.toBinaryString(ret)); // "100"
final var value = 7;
System.out.println(Integer.toBinaryString(value)); // "111"
final var ret = Integer.highestOneBit(value);
System.out.println(ret); // 4
System.out.println(Integer.toBinaryString(ret)); // "100"
final var value = 8;
System.out.println(Integer.toBinaryString(value)); // "1000"
final var ret = Integer.highestOneBit(value);
System.out.println(ret); // 8
System.out.println(Integer.toBinaryString(ret)); // "1000"
final var value = Integer.MAX_VALUE;
System.out.println(Integer.toBinaryString(value)); // "1111111111111111111111111111111"
final var ret = Integer.highestOneBit(value);
System.out.println(ret); // 1073741824
System.out.println(Integer.toBinaryString(ret)); // "1000000000000000000000000000000"
final var value = Integer.MIN_VALUE;
System.out.println(Integer.toBinaryString(value)); // "10000000000000000000000000000000"
final var ret = Integer.highestOneBit(value);
System.out.println(ret); // -2147483648
System.out.println(Integer.toBinaryString(ret)); // "10000000000000000000000000000000"
int intValue ()
final var value = Integer.valueOf(1234).intValue();
System.out.println(value); // 1234
final var value = Integer.valueOf(-4567).intValue();
System.out.println(value); // -4567
final var value = Integer.valueOf(Integer.MAX_VALUE).intValue();
System.out.println(value); // 2147483647
final var value = Integer.valueOf(Integer.MIN_VALUE).intValue();
System.out.println(value); // -2147483648
long longValue ()
final var value = Integer.valueOf(1234).longValue();
System.out.println(value); // 1234
final var value = Integer.valueOf(-4567).longValue();
System.out.println(value); // -4567
final var value = Integer.valueOf(Integer.MAX_VALUE).longValue();
System.out.println(value); // 2147483647
final var value = Integer.valueOf(Integer.MIN_VALUE).longValue();
System.out.println(value); // -2147483648
static int lowestOneBit (int i)
final var value = 0;
System.out.println(Integer.toBinaryString(value)); // "0"
final var result = Integer.lowestOneBit(value);
System.out.println(result); // 0
System.out.println(Integer.toBinaryString(result)); // "0"
final var value = 1;
System.out.println(Integer.toBinaryString(value)); // "1"
final var result = Integer.lowestOneBit(value);
System.out.println(result); // 1
System.out.println(Integer.toBinaryString(result)); // "1"
final var value = 2;
System.out.println(Integer.toBinaryString(value)); // "10"
final var result = Integer.lowestOneBit(value);
System.out.println(result); // 2
System.out.println(Integer.toBinaryString(result)); // "10"
final var value = 3;
System.out.println(Integer.toBinaryString(value)); // "11"
final var result = Integer.lowestOneBit(value);
System.out.println(result); // 1
System.out.println(Integer.toBinaryString(result)); // "1"
final var value = 4;
System.out.println(Integer.toBinaryString(value)); // "100"
final var result = Integer.lowestOneBit(value);
System.out.println(result); // 4
System.out.println(Integer.toBinaryString(result)); // "100"
final var value = 5;
System.out.println(Integer.toBinaryString(value)); // "101"
final var result = Integer.lowestOneBit(value);
System.out.println(result); // 1
System.out.println(Integer.toBinaryString(result)); // "1"
final var value = 6;
System.out.println(Integer.toBinaryString(value)); // "110"
final var result = Integer.lowestOneBit(value);
System.out.println(result); // 2
System.out.println(Integer.toBinaryString(result)); // "10"
final var value = 7;
System.out.println(Integer.toBinaryString(value)); // "111"
final var result = Integer.lowestOneBit(value);
System.out.println(result); // 1
System.out.println(Integer.toBinaryString(result)); // "1"
final var value = Integer.MAX_VALUE;
System.out.println(Integer.toBinaryString(value)); // "1111111111111111111111111111111"
final var result = Integer.lowestOneBit(value);
System.out.println(result); // 1
System.out.println(Integer.toBinaryString(result)); // "1"
final var value = Integer.MIN_VALUE;
System.out.println(Integer.toBinaryString(value)); // "10000000000000000000000000000000"
final var result = Integer.lowestOneBit(value);
System.out.println(result); // -2147483648
System.out.println(Integer.toBinaryString(result)); // "10000000000000000000000000000000"
static int max (int a, int b)
System.out.println(Integer.max(1, 1)); // 1
System.out.println(Integer.max(1, 999)); // 999
System.out.println(Integer.max(888, 2)); // 888
System.out.println(Integer.max(1, -999)); // 1
System.out.println(Integer.max(-888, 2)); // 2
System.out.println(Integer.max(-1, -2)); // -1
static int min (int a, int b)
System.out.println(Integer.min(1, 1)); // 1
System.out.println(Integer.min(1, 999)); // 1
System.out.println(Integer.min(888, 2)); // 2
System.out.println(Integer.min(1, -999)); // -999
System.out.println(Integer.min(-888, 2)); // -888
System.out.println(Integer.min(-1, -2)); // -2
static int numberOfLeadingZeros (int i)
final var value = 0;
System.out.println(Integer.toBinaryString(value)); // "0"
System.out.println(Integer.numberOfLeadingZeros(value)); // 32
final var value = 1;
System.out.println(Integer.toBinaryString(value)); // "1"
System.out.println(Integer.numberOfLeadingZeros(value)); // 31
final var value = 2;
System.out.println(Integer.toBinaryString(value)); // "10"
System.out.println(Integer.numberOfLeadingZeros(value)); // 30
final var value = 3;
System.out.println(Integer.toBinaryString(value)); // "11"
System.out.println(Integer.numberOfLeadingZeros(value)); // 30
final var value = 4;
System.out.println(Integer.toBinaryString(value)); // "100"
System.out.println(Integer.numberOfLeadingZeros(value)); // 29
final var value = 5;
System.out.println(Integer.toBinaryString(value)); // "101"
System.out.println(Integer.numberOfLeadingZeros(value)); // 29
final var value = 6;
System.out.println(Integer.toBinaryString(value)); // "110"
System.out.println(Integer.numberOfLeadingZeros(value)); // 29
final var value = 7;
System.out.println(Integer.toBinaryString(value)); // "111"
System.out.println(Integer.numberOfLeadingZeros(value)); // 29
final var value = 8;
System.out.println(Integer.toBinaryString(value)); // "1000"
System.out.println(Integer.numberOfLeadingZeros(value)); // 28
final var value = 16;
System.out.println(Integer.toBinaryString(value)); // "10000"
System.out.println(Integer.numberOfLeadingZeros(value)); // 27
final var value = 32;
System.out.println(Integer.toBinaryString(value)); // "100000"
System.out.println(Integer.numberOfLeadingZeros(value)); // 26
final var value = Integer.MAX_VALUE;
System.out.println(Integer.toBinaryString(value)); // "1111111111111111111111111111111"
System.out.println(Integer.numberOfLeadingZeros(value)); // 1
final var value = Integer.MIN_VALUE;
System.out.println(Integer.toBinaryString(value)); // "10000000000000000000000000000000"
System.out.println(Integer.numberOfLeadingZeros(value)); // 0
static int numberOfTrailingZeros (int i)
final var value = 0;
System.out.println(Integer.toBinaryString(value)); // "0"
System.out.println(Integer.numberOfTrailingZeros(value)); // 32
final var value = 1;
System.out.println(Integer.toBinaryString(value)); // "1"
System.out.println(Integer.numberOfTrailingZeros(value)); // 0
final var value = 2;
System.out.println(Integer.toBinaryString(value)); // "10"
System.out.println(Integer.numberOfTrailingZeros(value)); // 1
final var value = 3;
System.out.println(Integer.toBinaryString(value)); // "11"
System.out.println(Integer.numberOfTrailingZeros(value)); // 0
final var value = 4;
System.out.println(Integer.toBinaryString(value)); // "100"
System.out.println(Integer.numberOfTrailingZeros(value)); // 2
final var value = 5;
System.out.println(Integer.toBinaryString(value)); // "101"
System.out.println(Integer.numberOfTrailingZeros(value)); // 0
final var value = 6;
System.out.println(Integer.toBinaryString(value)); // "110"
System.out.println(Integer.numberOfTrailingZeros(value)); // 1
final var value = 7;
System.out.println(Integer.toBinaryString(value)); // "111"
System.out.println(Integer.numberOfTrailingZeros(value)); // 0
final var value = 8;
System.out.println(Integer.toBinaryString(value)); // "1000"
System.out.println(Integer.numberOfTrailingZeros(value)); // 3
final var value = 16;
System.out.println(Integer.toBinaryString(value)); // "10000"
System.out.println(Integer.numberOfTrailingZeros(value)); // 4
final var value = 32;
System.out.println(Integer.toBinaryString(value)); // "100000"
System.out.println(Integer.numberOfTrailingZeros(value)); // 5
final var value = Integer.MAX_VALUE;
System.out.println(Integer.toBinaryString(value)); // "1111111111111111111111111111111"
System.out.println(Integer.numberOfTrailingZeros(value)); // 0
final var value = Integer.MIN_VALUE;
System.out.println(Integer.toBinaryString(value)); // "10000000000000000000000000000000"
System.out.println(Integer.numberOfTrailingZeros(value)); // 31
static int parseInt (CharSequence s, int beginIndex, int endIndex, int radix)
Please see also : parseInt(String s, int radix)
final var s = "12345";
//Integer.parseInt(s, 0, 0, 10); // NumberFormatException
System.out.println(Integer.parseInt(s, 0, 1, 10)); // 1
System.out.println(Integer.parseInt(s, 0, 2, 10)); // 12
System.out.println(Integer.parseInt(s, 0, 3, 10)); // 123
System.out.println(Integer.parseInt(s, 0, 4, 10)); // 1234
System.out.println(Integer.parseInt(s, 0, 5, 10)); // 12345
//Integer.parseInt(s, 0, 6, 10); // IndexOutOfBoundsException
System.out.println(Integer.parseInt(s, 1, 5, 10)); // 2345
System.out.println(Integer.parseInt(s, 2, 5, 10)); // 345
System.out.println(Integer.parseInt(s, 3, 5, 10)); // 45
System.out.println(Integer.parseInt(s, 4, 5, 10)); // 5
static int parseInt (String s)
System.out.println(Integer.parseInt("0")); // 0
System.out.println(Integer.parseInt("123")); // 123
System.out.println(Integer.parseInt("+456")); // 456
System.out.println(Integer.parseInt("-789")); // -789
System.out.println(Integer.parseInt("2147483647")); // 2147483647
//Integer.parseInt("2147483648"); // NumberFormatException
System.out.println(Integer.parseInt("-2147483648")); // -2147483648
//Integer.parseInt("-2147483649"); // NumberFormatException
static int parseInt (String s, int radix)
System.out.println(Integer.parseInt("0", 10)); // 0
System.out.println(Integer.parseInt("473", 10)); // 473
System.out.println(Integer.parseInt("+42", 10)); // 42
System.out.println(Integer.parseInt("-0", 10)); // 0
System.out.println(Integer.parseInt("-FF", 16)); // -255
System.out.println(Integer.parseInt("1100110", 2)); // 102
System.out.println(Integer.parseInt("2147483647", 10)); // 2147483647
System.out.println(Integer.parseInt("-2147483648", 10)); // -2147483648
//Integer.parseInt("2147483648", 10); // NumberFormatException
//Integer.parseInt("99", 8); // NumberFormatException
//Integer.parseInt("Kona", 10); // NumberFormatException
System.out.println(Integer.parseInt("Kona", 27)); // 411787
static int parseUnsignedInt (CharSequence s, int beginIndex, int endIndex, int radix)
Please see also : parseUnsignedInt(String s, int radix)
final var s = "12345";
//Integer.parseUnsignedInt(s, 0, 0, 10); // NumberFormatException
System.out.println(Integer.parseUnsignedInt(s, 0, 1, 10)); // 1
System.out.println(Integer.parseUnsignedInt(s, 0, 2, 10)); // 12
System.out.println(Integer.parseUnsignedInt(s, 0, 3, 10)); // 123
System.out.println(Integer.parseUnsignedInt(s, 0, 4, 10)); // 1234
System.out.println(Integer.parseUnsignedInt(s, 0, 5, 10)); // 12345
//Integer.parseUnsignedInt(s, 0, 6, 10); // IndexOutOfBoundsException
System.out.println(Integer.parseUnsignedInt(s, 1, 5, 10)); // 2345
System.out.println(Integer.parseUnsignedInt(s, 2, 5, 10)); // 345
System.out.println(Integer.parseUnsignedInt(s, 3, 5, 10)); // 45
System.out.println(Integer.parseUnsignedInt(s, 4, 5, 10)); // 5
static int parseUnsignedInt (String s)
System.out.println(Integer.parseUnsignedInt("0")); // 0
System.out.println(Integer.parseUnsignedInt("123")); // 123
//Integer.parseUnsignedInt("-456"); // NumberFormatException
System.out.println(Integer.MAX_VALUE); // 2147483647
System.out.println(Integer.parseUnsignedInt("2147483647")); // 2147483647
System.out.println(Integer.parseUnsignedInt("2147483648")); // -2147483648
System.out.println(Integer.parseUnsignedInt("2147483649")); // -2147483647
static int parseUnsignedInt (String s, int radix)
System.out.println(Integer.parseUnsignedInt("0", 10)); // 0
System.out.println(Integer.parseUnsignedInt("123", 10)); // 123
//Integer.parseUnsignedInt("-456", 10); // NumberFormatException
System.out.println(Integer.MAX_VALUE); // 2147483647
System.out.println(Integer.parseUnsignedInt("2147483647", 10)); // 2147483647
System.out.println(Integer.parseUnsignedInt("2147483648", 10)); // -2147483648
System.out.println(Integer.parseUnsignedInt("2147483649", 10)); // -2147483647
System.out.println(Integer.parseUnsignedInt("FF", 16)); // 255
//Integer.parseUnsignedInt("-AA", 16); // NumberFormatException
System.out.println(Integer.parseUnsignedInt("1100110", 2)); // 102
//Integer.parseUnsignedInt("-1010"); // NumberFormatException
static int remainderUnsigned (int dividend, int divisor)
final var value = -1294967292;
System.out.println(Integer.toUnsignedString(value)); // 3000000004
System.out.println(Integer.remainderUnsigned(value, 10)); // 4
System.out.println(value % 10); // -2
Integer resolveConstantDesc (MethodHandles.Lookup lookup)
final var integer = Integer.valueOf(123);
final var ret = integer.resolveConstantDesc(MethodHandles.lookup());
System.out.println(ret); // 123
static int reverse (int i)
final var value = 0;
System.out.println(value); // 0
final var ret = Integer.reverse(value);
System.out.println(ret); // 0
System.out.println("-- print --");
System.out.println("%32s".formatted(Integer.toBinaryString(value)).replace(" ", "0"));
System.out.println("%32s".formatted(Integer.toBinaryString(ret)).replace(" ", "0"));
// Result
// ↓
//-- print --
//00000000000000000000000000000000
//00000000000000000000000000000000
final var value = 1;
System.out.println(value); // 1
final var ret = Integer.reverse(value);
System.out.println(ret); // -2147483648
System.out.println("-- print --");
System.out.println("%32s".formatted(Integer.toBinaryString(value)).replace(" ", "0"));
System.out.println("%32s".formatted(Integer.toBinaryString(ret)).replace(" ", "0"));
// Result
// ↓
//-- print --
//00000000000000000000000000000001
//10000000000000000000000000000000
final var value = 2;
System.out.println(value); // 2
final var ret = Integer.reverse(value);
System.out.println(ret); // 1073741824
System.out.println("-- print --");
System.out.println("%32s".formatted(Integer.toBinaryString(value)).replace(" ", "0"));
System.out.println("%32s".formatted(Integer.toBinaryString(ret)).replace(" ", "0"));
// Result
// ↓
//-- print --
//00000000000000000000000000000010
//01000000000000000000000000000000
final var value = 0x0f0f;
System.out.println(value); // 3855
final var ret = Integer.reverse(value);
System.out.println(ret); // -252706816
System.out.println("-- print --");
System.out.println("%32s".formatted(Integer.toBinaryString(value)).replace(" ", "0"));
System.out.println("%32s".formatted(Integer.toBinaryString(ret)).replace(" ", "0"));
// Result
// ↓
//-- print --
//00000000000000000000111100001111
//11110000111100000000000000000000
final var value = Integer.MAX_VALUE;
System.out.println(value); // 2147483647
final var ret = Integer.reverse(value);
System.out.println(ret); // -2
System.out.println("-- print --");
System.out.println("%32s".formatted(Integer.toBinaryString(value)).replace(" ", "0"));
System.out.println("%32s".formatted(Integer.toBinaryString(ret)).replace(" ", "0"));
// Result
// ↓
//-- print --
//01111111111111111111111111111111
//11111111111111111111111111111110
final var value = Integer.MIN_VALUE;
System.out.println(value); // -2147483648
final var ret = Integer.reverse(value);
System.out.println(ret); // 1
System.out.println("-- print --");
System.out.println("%32s".formatted(Integer.toBinaryString(value)).replace(" ", "0"));
System.out.println("%32s".formatted(Integer.toBinaryString(ret)).replace(" ", "0"));
// Result
// ↓
//-- print --
//10000000000000000000000000000000
//00000000000000000000000000000001
static int reverseBytes (int i)
final var value = 0x0;
final var ret = Integer.reverseBytes(value);
System.out.println("-- print --");
System.out.println("%8s".formatted(Integer.toHexString(value)).replace(" ", "0"));
System.out.println("%8s".formatted(Integer.toHexString(ret)).replace(" ", "0"));
// Result
// ↓
//-- print --
//00000000
//00000000
final var value = 0x1;
final var ret = Integer.reverseBytes(value);
System.out.println("-- print --");
System.out.println("%8s".formatted(Integer.toHexString(value)).replace(" ", "0"));
System.out.println("%8s".formatted(Integer.toHexString(ret)).replace(" ", "0"));
// Result
// ↓
//-- print --
//00000001
//01000000
final var value = 0xf;
final var ret = Integer.reverseBytes(value);
System.out.println("-- print --");
System.out.println("%8s".formatted(Integer.toHexString(value)).replace(" ", "0"));
System.out.println("%8s".formatted(Integer.toHexString(ret)).replace(" ", "0"));
// Result
// ↓
//-- print --
//0000000f
//0f000000
final var value = 0x10;
final var ret = Integer.reverseBytes(value);
System.out.println("-- print --");
System.out.println("%8s".formatted(Integer.toHexString(value)).replace(" ", "0"));
System.out.println("%8s".formatted(Integer.toHexString(ret)).replace(" ", "0"));
// Result
// ↓
//-- print --
//00000010
//10000000
final var value = 0x1f;
final var ret = Integer.reverseBytes(value);
System.out.println("-- print --");
System.out.println("%8s".formatted(Integer.toHexString(value)).replace(" ", "0"));
System.out.println("%8s".formatted(Integer.toHexString(ret)).replace(" ", "0"));
// Result
// ↓
//-- print --
//0000001f
//1f000000
final var value = 0x1234567;
final var ret = Integer.reverseBytes(value);
System.out.println("-- print --");
System.out.println("%8s".formatted(Integer.toHexString(value)).replace(" ", "0"));
System.out.println("%8s".formatted(Integer.toHexString(ret)).replace(" ", "0"));
// Result
// ↓
//-- print --
//01234567
//67452301
final var value = Integer.MAX_VALUE;
final var ret = Integer.reverseBytes(value);
System.out.println("-- print --");
System.out.println("%8s".formatted(Integer.toHexString(value)).replace(" ", "0"));
System.out.println("%8s".formatted(Integer.toHexString(ret)).replace(" ", "0"));
// Result
// ↓
//-- print --
//7fffffff
//ffffff7f
final var value = Integer.MIN_VALUE;
final var ret = Integer.reverseBytes(value);
System.out.println("-- print --");
System.out.println("%8s".formatted(Integer.toHexString(value)).replace(" ", "0"));
System.out.println("%8s".formatted(Integer.toHexString(ret)).replace(" ", "0"));
// Result
// ↓
//-- print --
//80000000
//00000080
static int rotateLeft (int i, int distance)
final int value = 1;
for (int i = 0; i < 33; i++) {
final var ret = Integer.rotateLeft(value, i);
System.out.printf("i = %2d : %s%n", i, Integer.toBinaryString(ret));
}
// Result
// ↓
//i = 0 : 1
//i = 1 : 10
//i = 2 : 100
//i = 3 : 1000
//i = 4 : 10000
//i = 5 : 100000
//i = 6 : 1000000
//i = 7 : 10000000
//i = 8 : 100000000
//i = 9 : 1000000000
//i = 10 : 10000000000
//i = 11 : 100000000000
//i = 12 : 1000000000000
//i = 13 : 10000000000000
//i = 14 : 100000000000000
//i = 15 : 1000000000000000
//i = 16 : 10000000000000000
//i = 17 : 100000000000000000
//i = 18 : 1000000000000000000
//i = 19 : 10000000000000000000
//i = 20 : 100000000000000000000
//i = 21 : 1000000000000000000000
//i = 22 : 10000000000000000000000
//i = 23 : 100000000000000000000000
//i = 24 : 1000000000000000000000000
//i = 25 : 10000000000000000000000000
//i = 26 : 100000000000000000000000000
//i = 27 : 1000000000000000000000000000
//i = 28 : 10000000000000000000000000000
//i = 29 : 100000000000000000000000000000
//i = 30 : 1000000000000000000000000000000
//i = 31 : 10000000000000000000000000000000
//i = 32 : 1
final int value = Integer.MAX_VALUE;
for (int i = 0; i < 33; i++) {
final var ret = Integer.rotateLeft(value, i);
System.out.printf("i = %2d : %32s%n", i, Integer.toBinaryString(ret));
}
// Result
// ↓
//i = 0 : 1111111111111111111111111111111
//i = 1 : 11111111111111111111111111111110
//i = 2 : 11111111111111111111111111111101
//i = 3 : 11111111111111111111111111111011
//i = 4 : 11111111111111111111111111110111
//i = 5 : 11111111111111111111111111101111
//i = 6 : 11111111111111111111111111011111
//i = 7 : 11111111111111111111111110111111
//i = 8 : 11111111111111111111111101111111
//i = 9 : 11111111111111111111111011111111
//i = 10 : 11111111111111111111110111111111
//i = 11 : 11111111111111111111101111111111
//i = 12 : 11111111111111111111011111111111
//i = 13 : 11111111111111111110111111111111
//i = 14 : 11111111111111111101111111111111
//i = 15 : 11111111111111111011111111111111
//i = 16 : 11111111111111110111111111111111
//i = 17 : 11111111111111101111111111111111
//i = 18 : 11111111111111011111111111111111
//i = 19 : 11111111111110111111111111111111
//i = 20 : 11111111111101111111111111111111
//i = 21 : 11111111111011111111111111111111
//i = 22 : 11111111110111111111111111111111
//i = 23 : 11111111101111111111111111111111
//i = 24 : 11111111011111111111111111111111
//i = 25 : 11111110111111111111111111111111
//i = 26 : 11111101111111111111111111111111
//i = 27 : 11111011111111111111111111111111
//i = 28 : 11110111111111111111111111111111
//i = 29 : 11101111111111111111111111111111
//i = 30 : 11011111111111111111111111111111
//i = 31 : 10111111111111111111111111111111
//i = 32 : 1111111111111111111111111111111
static int rotateRight (int i, int distance)
final int value = 1;
for (int i = 0; i < 33; i++) {
final var ret = Integer.rotateRight(value, i);
System.out.printf("i = %2d : %s%n", i, Integer.toBinaryString(ret));
}
// Result
// ↓
//i = 0 : 1
//i = 1 : 10000000000000000000000000000000
//i = 2 : 1000000000000000000000000000000
//i = 3 : 100000000000000000000000000000
//i = 4 : 10000000000000000000000000000
//i = 5 : 1000000000000000000000000000
//i = 6 : 100000000000000000000000000
//i = 7 : 10000000000000000000000000
//i = 8 : 1000000000000000000000000
//i = 9 : 100000000000000000000000
//i = 10 : 10000000000000000000000
//i = 11 : 1000000000000000000000
//i = 12 : 100000000000000000000
//i = 13 : 10000000000000000000
//i = 14 : 1000000000000000000
//i = 15 : 100000000000000000
//i = 16 : 10000000000000000
//i = 17 : 1000000000000000
//i = 18 : 100000000000000
//i = 19 : 10000000000000
//i = 20 : 1000000000000
//i = 21 : 100000000000
//i = 22 : 10000000000
//i = 23 : 1000000000
//i = 24 : 100000000
//i = 25 : 10000000
//i = 26 : 1000000
//i = 27 : 100000
//i = 28 : 10000
//i = 29 : 1000
//i = 30 : 100
//i = 31 : 10
//i = 32 : 1
final int value = Integer.MAX_VALUE;
for (int i = 0; i < 33; i++) {
final var ret = Integer.rotateRight(value, i);
System.out.printf("i = %2d : %32s%n", i, Integer.toBinaryString(ret));
}
// Result
// ↓
//i = 0 : 1111111111111111111111111111111
//i = 1 : 10111111111111111111111111111111
//i = 2 : 11011111111111111111111111111111
//i = 3 : 11101111111111111111111111111111
//i = 4 : 11110111111111111111111111111111
//i = 5 : 11111011111111111111111111111111
//i = 6 : 11111101111111111111111111111111
//i = 7 : 11111110111111111111111111111111
//i = 8 : 11111111011111111111111111111111
//i = 9 : 11111111101111111111111111111111
//i = 10 : 11111111110111111111111111111111
//i = 11 : 11111111111011111111111111111111
//i = 12 : 11111111111101111111111111111111
//i = 13 : 11111111111110111111111111111111
//i = 14 : 11111111111111011111111111111111
//i = 15 : 11111111111111101111111111111111
//i = 16 : 11111111111111110111111111111111
//i = 17 : 11111111111111111011111111111111
//i = 18 : 11111111111111111101111111111111
//i = 19 : 11111111111111111110111111111111
//i = 20 : 11111111111111111111011111111111
//i = 21 : 11111111111111111111101111111111
//i = 22 : 11111111111111111111110111111111
//i = 23 : 11111111111111111111111011111111
//i = 24 : 11111111111111111111111101111111
//i = 25 : 11111111111111111111111110111111
//i = 26 : 11111111111111111111111111011111
//i = 27 : 11111111111111111111111111101111
//i = 28 : 11111111111111111111111111110111
//i = 29 : 11111111111111111111111111111011
//i = 30 : 11111111111111111111111111111101
//i = 31 : 11111111111111111111111111111110
//i = 32 : 1111111111111111111111111111111
short shortValue ()
final var ret1 = Integer.valueOf(0).shortValue();
System.out.println(ret1); // 0
final var ret2 = Integer.valueOf(123).shortValue();
System.out.println(ret2); // 123
final var ret3 = Integer.valueOf(-456).shortValue();
System.out.println(ret3); // -456
final var ret1 = Integer.valueOf(Short.MAX_VALUE).shortValue();
System.out.println(ret1); // 32767
final var ret2 = Integer.valueOf(Short.MIN_VALUE).shortValue();
System.out.println(ret2); // -32768
final var ret1 = Integer.valueOf(32767).shortValue();
System.out.println(ret1); // 32767
final var ret3 = Integer.valueOf(32768).shortValue();
System.out.println(ret3); // -32768
final var ret4 = Integer.valueOf(32769).shortValue();
System.out.println(ret4); // -32767
final var ret1 = Integer.valueOf(-32768).shortValue();
System.out.println(ret1); // -32768
final var ret3 = Integer.valueOf(-32769).shortValue();
System.out.println(ret3); // 32767
final var ret4 = Integer.valueOf(-32770).shortValue();
System.out.println(ret4); // 32766
static int signum (int i)
System.out.println(Integer.signum(100)); // 1
System.out.println(Integer.signum(-100)); // -1
System.out.println(Integer.signum(0)); // 0
System.out.println(Integer.signum(-0)); // 0
System.out.println(Integer.signum(Integer.MAX_VALUE)); // 1
System.out.println(Integer.signum(Integer.MIN_VALUE)); // -1
static int sum (int a, int b)
System.out.println(Integer.sum(100, 200)); // 300
System.out.println(Integer.sum(-300, 200)); // -100
System.out.println(Integer.sum(Integer.MAX_VALUE, Integer.MIN_VALUE)); // -1
System.out.println(Integer.sum(Integer.MAX_VALUE, 1)); // -2147483648
System.out.println(Integer.sum(Integer.MIN_VALUE, -1)); // 2147483647
static String toBinaryString (int i)
System.out.println(Integer.toBinaryString(0)); // "0"
System.out.println(Integer.toBinaryString(1)); // "1"
System.out.println(Integer.toBinaryString(2)); // "10"
System.out.println(Integer.toBinaryString(3)); // "11"
System.out.println(Integer.toBinaryString(4)); // "100"
System.out.println(Integer.toBinaryString(5)); // "101"
System.out.println(Integer.toBinaryString(6)); // "110"
System.out.println(Integer.toBinaryString(7)); // "111"
System.out.println(Integer.toBinaryString(8)); // "1000"
System.out.println(Integer.toBinaryString(-1)); // "11111111111111111111111111111111"
System.out.println(Integer.toBinaryString(-2)); // "11111111111111111111111111111110"
System.out.println(Integer.toBinaryString(-3)); // "11111111111111111111111111111101"
System.out.println(Integer.toBinaryString(Integer.MAX_VALUE)); // "1111111111111111111111111111111"
System.out.println(Integer.toBinaryString(Integer.MIN_VALUE)); // "10000000000000000000000000000000"
static String toHexString (int i)
System.out.println(Integer.toHexString(0)); // "0"
System.out.println(Integer.toHexString(1)); // "1"
System.out.println(Integer.toHexString(2)); // "2"
System.out.println(Integer.toHexString(3)); // "3"
System.out.println(Integer.toHexString(4)); // "4"
System.out.println(Integer.toHexString(5)); // "5"
System.out.println(Integer.toHexString(6)); // "6"
System.out.println(Integer.toHexString(7)); // "7"
System.out.println(Integer.toHexString(8)); // "8"
System.out.println(Integer.toHexString(9)); // "9"
System.out.println(Integer.toHexString(10)); // "a"
System.out.println(Integer.toHexString(11)); // "b"
System.out.println(Integer.toHexString(12)); // "c"
System.out.println(Integer.toHexString(13)); // "d"
System.out.println(Integer.toHexString(14)); // "e"
System.out.println(Integer.toHexString(15)); // "f"
System.out.println(Integer.toHexString(16)); // "10"
System.out.println(Integer.toHexString(17)); // "11"
System.out.println(Integer.toHexString(-1)); // "ffffffff"
System.out.println(Integer.toHexString(-2)); // "fffffffe"
System.out.println(Integer.toHexString(-3)); // "fffffffd"
System.out.println(Integer.toHexString(Integer.MAX_VALUE)); // "7fffffff"
System.out.println(Integer.toHexString(Integer.MIN_VALUE)); // "80000000"
static String toOctalString (int i)
System.out.println(Integer.toOctalString(0)); // "0"
System.out.println(Integer.toOctalString(1)); // "1"
System.out.println(Integer.toOctalString(2)); // "2"
System.out.println(Integer.toOctalString(3)); // "3"
System.out.println(Integer.toOctalString(4)); // "4"
System.out.println(Integer.toOctalString(5)); // "5"
System.out.println(Integer.toOctalString(6)); // "6"
System.out.println(Integer.toOctalString(7)); // "7"
System.out.println(Integer.toOctalString(8)); // "10"
System.out.println(Integer.toOctalString(9)); // "11"
System.out.println(Integer.toOctalString(10)); // "12"
System.out.println(Integer.toOctalString(11)); // "13"
System.out.println(Integer.toOctalString(-1)); // "37777777777"
System.out.println(Integer.toOctalString(-2)); // "37777777776"
System.out.println(Integer.toOctalString(-3)); // "37777777775"
System.out.println(Integer.toOctalString(Integer.MAX_VALUE)); // "17777777777"
System.out.println(Integer.toOctalString(Integer.MIN_VALUE)); // "20000000000"
String toString ()
final var ret1 = Integer.valueOf(123).toString();
System.out.println(ret1); // "123"
final var ret2 = Integer.valueOf(-456).toString();
System.out.println(ret2); // "-456"
static String toString (int i)
final var ret1 = Integer.toString(123);
System.out.println(ret1); // "123"
final var ret2 = Integer.toString(-456);
System.out.println(ret2); // "-456"
System.out.println(Integer.toString(Integer.MAX_VALUE)); // "2147483647"
System.out.println(Integer.toString(Integer.MIN_VALUE)); // "-2147483648"
static String toString (int i, int radix)
final var ret1 = Integer.toString(123, 10);
System.out.println(ret1); // "123"
final var ret2 = Integer.toString(-456, 10);
System.out.println(ret2); // "-456"
System.out.println(Integer.toString(Integer.MAX_VALUE, 10)); // "2147483647"
System.out.println(Integer.toString(Integer.MIN_VALUE, 10)); // "-2147483648"
// Hexadecimal
final var ret1 = Integer.toString(255, 16); // "ff"
System.out.println(ret1);
final var ret2 = Integer.toString(-128, 16); // "-80"
System.out.println(ret2);
System.out.println(Integer.toString(Integer.MAX_VALUE, 16)); // "7fffffff"
System.out.println(Integer.toString(Integer.MIN_VALUE, 16)); // "-80000000"
static long toUnsignedLong (int x)
System.out.println(Integer.toUnsignedLong(0)); // 0
System.out.println(Integer.toUnsignedLong(123)); // 123
System.out.println(Integer.toUnsignedLong(Integer.MAX_VALUE)); // 2147483647
System.out.println(Integer.toUnsignedLong(Integer.MIN_VALUE)); // 2147483648
System.out.println(Integer.toUnsignedLong(-1)); // 4294967295
System.out.println(Integer.toUnsignedLong(-2)); // 4294967294
System.out.println(Integer.toUnsignedLong(-3)); // 4294967293
static String toUnsignedString (int i)
System.out.println(Integer.toUnsignedString(0)); // "0"
System.out.println(Integer.toUnsignedString(123)); // "123"
System.out.println(Integer.toUnsignedString(Integer.MAX_VALUE)); // "2147483647"
System.out.println(Integer.toUnsignedString(Integer.MIN_VALUE)); // "2147483648"
System.out.println(Integer.toUnsignedString(-1)); // "4294967295"
System.out.println(Integer.toUnsignedString(-2)); // "4294967294"
System.out.println(Integer.toUnsignedString(-3)); // "4294967293"
static String toUnsignedString (int i, int radix)
System.out.println(Integer.toUnsignedString(0, 10)); // "0"
System.out.println(Integer.toUnsignedString(123, 10)); // "123"
System.out.println(Integer.toUnsignedString(Integer.MAX_VALUE, 10)); // "2147483647"
System.out.println(Integer.toUnsignedString(Integer.MIN_VALUE, 10)); // "2147483648"
System.out.println(Integer.toUnsignedString(-1, 10)); // "4294967295"
System.out.println(Integer.toUnsignedString(-2, 10)); // "4294967294"
System.out.println(Integer.toUnsignedString(-3, 10)); // "4294967293"
// Character.MAX_RADIX = 36
for (int i = 0; i < Character.MAX_RADIX + 1; i++) {
//i = 0 : 0
//i = 1 : 1
//i = 2 : 2
//i = 3 : 3
//i = 4 : 4
//i = 5 : 5
//i = 6 : 6
//i = 7 : 7
//i = 8 : 8
//i = 9 : 9
//i = 10 : a
//i = 11 : b
//i = 12 : c
//i = 13 : d
//i = 14 : e
//i = 15 : f
//i = 16 : g
//i = 17 : h
//i = 18 : i
//i = 19 : j
//i = 20 : k
//i = 21 : l
//i = 22 : m
//i = 23 : n
//i = 24 : o
//i = 25 : p
//i = 26 : q
//i = 27 : r
//i = 28 : s
//i = 29 : t
//i = 30 : u
//i = 31 : v
//i = 32 : w
//i = 33 : x
//i = 34 : y
//i = 35 : z
//i = 36 : 10
System.out.printf("i = %2d : %s%n", i, Integer.toUnsignedString(i, Character.MAX_RADIX));
}
System.out.println(Integer.toUnsignedString(0, Character.MAX_RADIX)); // "0"
System.out.println(Integer.toUnsignedString(1234, Character.MAX_RADIX)); // "ya"
System.out.println(Integer.toUnsignedString(-1, Character.MAX_RADIX)); // "1z141z3"
System.out.println(Integer.toUnsignedString(-2, Character.MAX_RADIX)); // "1z141z2"
System.out.println(Integer.toUnsignedString(-3, Character.MAX_RADIX)); // "1z141z1"
System.out.println(Integer.toUnsignedString(Integer.MAX_VALUE, Character.MAX_RADIX)); // "zik0zj"
System.out.println(Integer.toUnsignedString(Integer.MIN_VALUE, Character.MAX_RADIX)); // "zik0zk"
static Integer valueOf (int i)
System.out.println(Integer.valueOf(0)); // 0
System.out.println(Integer.valueOf(1)); // 1
System.out.println(Integer.valueOf(2)); // 2
System.out.println(Integer.valueOf(100)); // 100
System.out.println(Integer.valueOf(9999)); // 9999
System.out.println(Integer.valueOf(-1)); // -1
System.out.println(Integer.valueOf(-2)); // -2
System.out.println(Integer.valueOf(-3)); // -3
System.out.println(Integer.valueOf(Integer.MAX_VALUE)); // 2147483647
System.out.println(Integer.valueOf(Integer.MIN_VALUE)); // -2147483648
static Integer valueOf (String s)
System.out.println(Integer.valueOf("0")); // 0
System.out.println(Integer.valueOf("123")); // 123
System.out.println(Integer.valueOf("+456")); // 456
System.out.println(Integer.valueOf("-789")); // -789
System.out.println(Integer.valueOf("2147483647")); // 2147483647
//Integer.valueOf("2147483648"); // NumberFormatException
System.out.println(Integer.valueOf("-2147483648")); // -2147483648
//Integer.valueOf("-2147483649"); // NumberFormatException
static Integer valueOf (String s, int radix)
System.out.println(Integer.valueOf("0", 10)); // 0
System.out.println(Integer.valueOf("473", 10)); // 473
System.out.println(Integer.valueOf("+42", 10)); // 42
System.out.println(Integer.valueOf("-0", 10)); // 0
System.out.println(Integer.valueOf("-FF", 16)); // -255
System.out.println(Integer.valueOf("1100110", 2)); // 102
System.out.println(Integer.valueOf("2147483647", 10)); // 2147483647
System.out.println(Integer.valueOf("-2147483648", 10)); // -2147483648
//Integer.valueOf("2147483648", 10); // NumberFormatException
//Integer.valueOf("99", 8); // NumberFormatException
//Integer.valueOf("Kona", 10); // NumberFormatException
System.out.println(Integer.valueOf("Kona", 27)); // 411787