Java byteValue()方法
byteValue()方法
Java中的byteValue()方法,可以将继承自Number类的Java对象转换为byte形式的数值。其语法如下:
NumberObj.byteValue()
提示:继承自Number类的包装类主要包括Byte、Integer、Short、Long、Double、Float等几种!
byteValue()方法实例代码
下方实例中,将Java中的Integer、Short、Long、Double、Float等类型对象转换为byte值:
public class test {
public static void main(String[] args) {
Integer a = 1;
byte x = a.byteValue();
Float b = 0.2f;
byte y = b.byteValue();
Double c = 3.1;
byte z = c.byteValue();
Long d = 6L;
byte m = d.byteValue();
Short e = 2;
byte n = e.byteValue();
System.out.println("x="+x+",y="+y+",z="+z+",m="+m+",n="+n);
}
}
免责声明:内容仅供参考,不保证正确性!