java Integer类的byteValue()方法怎样使用?

写一个例子就好,能说明原因更好谢谢。
2025-06-21 09:20:44
推荐回答(1个)
回答1:

该方法的作用是以byte类型返回该 Integer 的值。只取低八位的值,高位不要。

函数原型:

public byte byteValue()

所属包:

java.lang.Integer

示例:

public class IntegerDemo {
   public static void main(String[] args) {
     Integer obj = new Integer(10);
     // returns the value of Integer as a byte
     byte b = obj.byteValue();
     System.out.println("Value of b = " + b);//输出Value of b = 10
   }
}