Java Byte intValue()方法及示例
Byte类的 intValue() 方法是Java中的一个内置方法,用于将该Byte对象的值返回为int。
语法
ByteObject.intValue()
返回值: 它返回ByteObject的值为int。
下面是intValue()方法在Java中的实现。
例1 :
// Java code to demonstrate// Byte intValue() method class GFG { public static void main(String[] args) { // byte value byte a = 17; // wrapping the byte value // in the wrapper class Byte Byte b = new Byte(a); // intValue of the Byte Object int output = b.intValue(); // printing the output System.out.println("Integer value of " + a + " is : " + output); }}
输出:
Integer value of 17 is : 17
例2 :
// Java code to demonstrate// Byte intValue() method class GFG { public static void main(String[] args) { String value = "17"; // wrapping the byte value // in the wrapper class Byte Byte b = new Byte(value); // intValue of the Byte Object int output = b.intValue(); // printing the output System.out.println("Integer value of " + b + " is : " + output); }}
输出:
Integer value of 17 is : 17
