在 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