Java 整數 byteValue() 方法
byteValue() 方法將此 Integer 的值返回為一個位元組。
以下是 Java 中 byteValue() 方法的實現示例 −
示例
public class Main { public static void main(String[] args) { Integer val = new Integer(10); byte res = val.byteValue(); System.out.println("Value = " + res); } }
輸出
Value = 10
我們再看一個示例 −
示例
import java.util.*; public class Main { public static void main(String[] args) { Byte b = new Byte("10"); byte res = b.byteValue(); System.out.println("Byte = " + b ); System.out.println("Primitive byte = "+ res); } }
輸出
Byte = 80 Primitive byte = 80
廣告