Java : Integer con ejemplos
Integer (Java SE 24 & JDK 24) en Java con ejemplos.
Encontrará muestras de código para la mayoría de los métodos Integer.
Nota :
- Este artículo puede utilizar software de traducción para su comodidad. Consulte también la versión original en inglés.
Summary
La clase Integer es la clase contenedora de valores de tipo primitivo int. Un objeto de tipo Integer contiene un único campo de tipo int. (Traducción automática)
// 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
El número de bytes utilizados para representar un valor int en forma binaria de complemento a dos. (Traducción automática)
System.out.println(Integer.BYTES); // 4
static final int MAX_VALUE
Una constante que contiene el valor máximo que puede tener un int, 231-1. (Traducción automática)
System.out.println(Integer.MAX_VALUE); // 2147483647
System.out.println("0x" + Integer.toHexString(Integer.MAX_VALUE)); // "0x7fffffff"
static final int MIN_VALUE
Una constante que contiene el valor mínimo que puede tener un int, -231. (Traducción automática)
System.out.println(Integer.MIN_VALUE); // -2147483648
System.out.println("0x" + Integer.toHexString(Integer.MIN_VALUE)); // "0x80000000"
static final int SIZE
La cantidad de bits utilizados para representar un valor int en forma binaria de complemento a dos. (Traducción automática)
System.out.println(Integer.SIZE); // 32
static final Class<Integer> TYPE
La instancia de clase que representa el tipo primitivo int. (Traducción automática)
System.out.println(Integer.TYPE.getSimpleName()); // "int"
System.out.println(Integer.TYPE.isPrimitive()); // true
Constructors
Integer (int value)
Obsoleto, para eliminación: Este elemento de API está sujeto a eliminación en una versión futura. Rara vez es apropiado usar este constructor. (Traducción automática)
Deprecated.
Integer (String s)
Obsoleto, para eliminación: Este elemento de API está sujeto a eliminación en una versión futura. Rara vez es apropiado usar este constructor. (Traducción automática)
Deprecated.
Methods
static int bitCount (int i)
Devuelve la cantidad de bits uno en la representación binaria de complemento a dos del valor int especificado. (Traducción automática)
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 ()
Devuelve el valor de este entero como un byte después de una conversión primitiva de estrechamiento. (Traducción automática)
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)
Compara numéricamente dos valores int. (Traducción automática)
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)
Compara numéricamente dos objetos enteros. (Traducción automática)
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)
Compara dos valores int numéricamente y trata los valores como sin signo. (Traducción automática)
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.compare(value1, value2)); // 0
System.out.println(Integer.compareUnsigned(value1, value2)); // 0
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.compare(value1, value2)); // -1
System.out.println(Integer.compareUnsigned(value1, value2)); // -1
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.compare(value1, value2)); // -1
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.compare(value1, value2)); // 1
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.compare(value1, value2)); // 1
System.out.println(Integer.compareUnsigned(value1, value2)); // -1
static int compress (int i, int mask)
Devuelve el valor obtenido al comprimir los bits del valor int especificado, i, de acuerdo con la máscara de bits especificada. (Traducción automática)
final var i = 0xcafebabe;
final var mask = 0xff00fff0;
final var compressed = Integer.compress(i, mask);
System.out.printf("%#x%n", compressed); // 0xcabab
final var expanded = Integer.expand(compressed, mask);
System.out.printf("%#x%n", expanded); // 0xca00bab0
static Integer decode (String nm)
Decodifica una cadena en un entero. (Traducción automática)
// Decimal
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 ()
Devuelve un Opcional que contiene el descriptor nominal para esta instancia, que es la instancia misma. (Traducción automática)
final var ret = Integer.valueOf(123).describeConstable();
System.out.println(ret); // Optional[123]
static int divideUnsigned (int dividend, int divisor)
Devuelve el cociente sin signo de dividir el primer argumento por el segundo, donde cada argumento y el resultado se interpretan como un valor sin signo. (Traducción automática)
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 ()
Devuelve el valor de este entero como un doble después de una conversión primitiva de ampliación. (Traducción automática)
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)
Compara este objeto con el objeto especificado. (Traducción automática)
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
static int expand (int i, int mask)
Devuelve el valor obtenido al expandir los bits del valor int especificado, i, de acuerdo con la máscara de bits especificada. (Traducción automática)
final var i = 0xcafebabe;
final var mask = 0xff00fff0;
final var compressed = Integer.compress(i, mask);
System.out.printf("%#x%n", compressed); // 0xcabab
final var expanded = Integer.expand(compressed, mask);
System.out.printf("%#x%n", expanded); // 0xca00bab0
float floatValue ()
Devuelve el valor de este entero como un flotante después de una conversión primitiva de ampliación. (Traducción automática)
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.1474836E9
final var value = Integer.valueOf(Integer.MIN_VALUE).floatValue();
System.out.println(value); // -2.1474836E9
static Integer getInteger (String nm)
Determina el valor entero de la propiedad del sistema con el nombre especificado. (Traducción automática)
final var key = "java.specification.version";
System.out.println(Integer.getInteger(key)); // 24
System.out.println(System.getProperty(key)); // "24"
final var key = "os.name";
System.out.println(Integer.getInteger(key)); // null
System.out.println(System.getProperty(key)); // "Windows 11"
static Integer getInteger (String nm, int val)
Determina el valor entero de la propiedad del sistema con el nombre especificado. (Traducción automática)
final var key = "java.specification.version";
System.out.println(Integer.getInteger(key, 999)); // 24
System.out.println(System.getProperty(key)); // "24"
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 11"
static Integer getInteger (String nm, Integer val)
Devuelve el valor entero de la propiedad del sistema con el nombre especificado. (Traducción automática)
final var key = "java.specification.version";
System.out.println(Integer.getInteger(key, Integer.valueOf(999))); // 24
System.out.println(System.getProperty(key)); // "24"
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 11"
int hashCode ()
Devuelve un código hash para este entero. (Traducción automática)
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)
Devuelve un código hash para un valor int; compatible con Integer.hashCode(). (Traducción automática)
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)
Devuelve un valor int con como máximo un único bit, en la posición del bit de orden más alto ("más a la izquierda") en el valor int especificado. (Traducción automática)
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 ()
Devuelve el valor de este entero como un int. (Traducción automática)
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 ()
Devuelve el valor de este entero como un valor largo después de una conversión primitiva de ampliación. (Traducción automática)
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)
Devuelve un valor int con como máximo un solo bit, en la posición del bit de orden más bajo ("más a la derecha") en el valor int especificado. (Traducción automática)
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)
Devuelve el mayor de dos valores int como si llamara a Math.max. (Traducción automática)
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)
Devuelve el menor de dos valores int como si llamara a Math.min. (Traducción automática)
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)
Devuelve la cantidad de bits cero que preceden al bit de orden más alto ("más a la izquierda") en la representación binaria de complemento a dos del valor int especificado. (Traducción automática)
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)
Devuelve la cantidad de bits cero que siguen al bit de orden más bajo ("más a la derecha") en la representación binaria de complemento a dos del valor int especificado. (Traducción automática)
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)
Analiza el argumento CharSequence como un int con signo en el radio especificado, comenzando en el beginIndex especificado y extendiéndose hasta endIndex - 1. (Traducción automática)
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)
Analiza el argumento de cadena como un entero decimal con signo. (Traducción automática)
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)
Analiza el argumento de cadena como un entero con signo en el radio especificado por el segundo argumento. (Traducción automática)
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)
Analiza el argumento CharSequence como un int sin signo en el radio especificado, comenzando en el beginIndex especificado y extendiéndose hasta endIndex - 1. (Traducción automática)
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)
Analiza el argumento de cadena como un entero decimal sin signo. (Traducción automática)
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)
Analiza el argumento de cadena como un entero sin signo en el radio especificado por el segundo argumento. (Traducción automática)
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)
Devuelve el resto sin signo de dividir el primer argumento por el segundo, donde cada argumento y el resultado se interpretan como un valor sin signo. (Traducción automática)
final var value = -1294967292;
System.out.println(value % 10); // -2
System.out.println(Integer.toUnsignedString(value)); // 3000000004
System.out.println(Integer.remainderUnsigned(value, 10)); // 4
Integer resolveConstantDesc (MethodHandles.Lookup lookup)
Resuelve esta instancia como una ConstantDesc, cuyo resultado es la instancia misma. (Traducción automática)
final var integer = Integer.valueOf(123);
final var ret = integer.resolveConstantDesc(MethodHandles.lookup());
System.out.println(ret); // 123
static int reverse (int i)
Devuelve el valor obtenido al invertir el orden de los bits en la representación binaria de complemento a dos del valor int especificado. (Traducción automática)
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)
Devuelve el valor obtenido al invertir el orden de los bytes en la representación del complemento a dos del valor int especificado. (Traducción automática)
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)
Devuelve el valor obtenido al rotar la representación binaria de complemento a dos del valor int especificado a la izquierda del número especificado de bits. (Traducción automática)
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)
Devuelve el valor obtenido al rotar hacia la derecha la representación binaria de complemento a dos del valor int especificado por la cantidad especificada de bits. (Traducción automática)
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 ()
Devuelve el valor de este entero como un valor corto después de una conversión primitiva de restricción. (Traducción automática)
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)
Devuelve la función signum del valor int especificado. (Traducción automática)
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)
Suma dos números enteros según el operador +. (Traducción automática)
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)
Devuelve una representación de cadena del argumento entero como un entero sin signo en base 2. (Traducción automática)
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)
Devuelve una representación de cadena del argumento entero como un entero sin signo en base 16. (Traducción automática)
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)
Devuelve una representación de cadena del argumento entero como un entero sin signo en base 8. (Traducción automática)
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 ()
Devuelve un objeto String que representa el valor de este entero. (Traducción automática)
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)
Devuelve un objeto String que representa el entero especificado. (Traducción automática)
final var ret1 = Integer.toString(123);
System.out.println(ret1); // "123"
final var ret2 = Integer.toString(-456);
System.out.println(ret2); // "-456"
final var ret3 = Integer.toString(Integer.MAX_VALUE);
System.out.println(ret3); // "2147483647"
final var ret4 = Integer.toString(Integer.MIN_VALUE);
System.out.println(ret4); // "-2147483648"
static String toString (int i, int radix)
Devuelve una representación de cadena del primer argumento en el radio especificado por el segundo argumento. (Traducción automática)
// Decimal
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)
Convierte el argumento en un largo mediante una conversión sin signo. (Traducción automática)
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)
Devuelve una representación de cadena del argumento como un valor decimal sin signo. (Traducción automática)
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)
Devuelve una representación de cadena del primer argumento como un valor entero sin signo en el radio especificado por el segundo argumento. (Traducción automática)
// Decimal
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)
Devuelve una instancia de Integer que representa el valor int especificado. (Traducción automática)
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)
Devuelve un objeto entero que contiene el valor de la cadena especificada. (Traducción automática)
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)
Devuelve un objeto entero que contiene el valor extraído de la cadena especificada cuando se analiza con el radio dado por el segundo argumento. (Traducción automática)
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
Related posts
- Ejemplos de API