在 Java 中將 Byte 轉換為數字基本資料型別
要將 Byte 轉換為數字基本資料型別,請使用以下方法 -
byteValue() shortValue() intValue() longValue() floatValue()
首先,讓我們宣告一個 Byte。
Byte byteVal = new Byte("35");現在,讓我們看看如何將其轉換為長型別,這是一個簡單的示例。
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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP