English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
要将Byte转换为数字原始数据类型,请使用以下方法-
byteValue() shortValue() intValue() longValue() floatValue()
首先,让我们声明一个字节。
Byte byteVal = new byte("35");
现在,让我们来看一个简单的示例,如何将其转换为long类型。
long longVal = byteVal.longValue(); System.out.println(longVal);
以相同的方式,您可以将其转换为其他原始数据类型,如下面完整的示例所示-
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); } }
输出结果
35 35 35 35 35.0 35.0