คลาส Byte เป็น subclass ของ Number และ wrap ค่า primitive type byte ไว้ในออบเจ็กต์ ออบเจ็กต์แบบ Byte มี field เดียวที่เป็น byte เมธอดสำคัญของ Byte ได้แก่ byteValue(), compare(), compareTo(), decode(), parseByte(), valueOf() เป็นต้น เราสามารถแปลงค่า hexadecimal เป็น byte โดยใช้เมธอด decode().byteValue() ของคลาส Byte
Syntax
public final class Byte extends Number implements Comparable<Byte>
ตัวอย่าง
public class ConvertHexaDecimalToByte {
public static void main(String args[]) {
byte b = Byte.decode("0x0a").byteValue(); // แปลง hexadecimal value เป็น byte
System.out.println(b);
}
}
Output
10