English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Para convertir Byte a tipos de datos de números primitivos, utilice los siguientes métodos-
byteValue() shortValue() intValue() longValue() floatValue()
Primero, declaramos un byte.
Byte byteVal = new byte("35");
Ahora, veamos un ejemplo simple de cómo convertirlo a tipo long.
long longVal = byteVal.longValue(); System.out.println(longVal);
De la misma manera, puede convertirlo a otros tipos de datos primitivos, como se muestra en el siguiente ejemplo completo-
public class Demo { public static void main(String args[]) { //byte byte byteVal = new byte("35"); byte b = byteVal.byteValue(); System.out.println(b); short shortVal = byteVal.shortValue(); System.out.println(shortVal); int intVal = byteVal.intValue(); System.out.println(intVal); long longVal = byteVal.longValue(); System.out.println(longVal); float floatVal = byteVal.floatValue(); System.out.println(floatVal); double doubleVal = byteVal.doubleValue(); System.out.println(doubleVal); } }
Resultado de salida
35 35 35 35 35.0 35.0