Byte 基本数据类型byte 的包装类
Byte 类型的对象包含一个 byte类型的字段
属性简介
构造方法
Byte的构造方法也是有两种
可以通过基本类型byte 或者字符串形式
Byte(byte value) | ![]() |
Byte(String s) | ![]() |
常用方法
比较
static int compare(byte x, byte y) | 静态方法 x<y 小于0 x=y 等于0 x>y 大于0 ![]() |
int compareTo(Byte anotherByte) | 实例方法 调用静态方法处理两个对象内部value的值 ![]() |
parseXXX系列
字符串解析 为 基本类型,
不需要对象,所以都是静态方法
valueOf系列
把基本基本类型 包装为对象
用来创建获得对象,所以无需对象,全都是静态方法
VaueOf系列都有对应的缓存区, 缓存区范围内对象为同一个
缓冲区为静态内部类中的数组
decode
Byte也提供了decode方法 可以解析带有前缀的字符串 实际使用的是Integer的decode 然后将数值强转为byte |
![]() |
XXXValue系列
获取对象的某种基本类型的值
需要获取对象的所以必然全部都是实例方法
强制类型转换的形式,将内部的 byte 值转换为指定的类型
类似 Integer和Long Byte也有提供XXXValue系列方法,原理也跟他们类似 全部都是强转 |
byteValue() shortValue() intValue() longValue() floatValue() doubleValue() |
toString toXXXString 系列
static String toString(byte b) | 静态方法![]() |
String toString() | 实例方法![]() |
static int toUnsignedInt(byte x) | 静态方法![]() |
static long toUnsignedLong(byte x) | 静态方法![]() |
hashcode
static int hashCode(byte value) | 静态方法![]() |
int hashCode() | 实例方法 同Integer和Long一样,调用的静态方法的形式 ![]() |
equals(Object)
重写了equals方法 内部比较的是对象的值 |
![]() |
可以看得出来,Byte中的方法相对于Integer和Long少了很多
而且有些还是借助于Integer中的方法