Java.lang.Byte.intValue() 方法
描述
java.lang.Byte.intValue() 将此 Byte 的值作为 int 返回。
声明
以下是 java.lang.Byte.intValue() 方法的声明。
public int intValue()
指定者
intValue 类 Number
参数
NA
返回值
该方法返回该对象转换为int类型后所表示的数值。
异常
NA
示例
下面的例子展示了 lang.Byte.intValue() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class ByteDemo {
public static void main(String[] args) {
// create 2 Byte objects b1, b2
Byte b1, b2;
// create 2 int i1, i2
int i1, i2;
// assign values to b1, b2
b1 = new Byte("123");
b2 = new Byte("-32");
// assign int values of b1, b2 to i1, i2
i1 = b1.intValue();
i2 = b2.intValue();
String str1 = "int value of Byte " + b1 + " is " + i1;
String str2 = "int value of Byte " + b2 + " is " + i2;
// print i1, i2 values
System.out.println( str1 );
System.out.println( str2 );
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
int value of Byte 123 is 123 int value of Byte -32 is -32

