[四]基础数据概述之Byte详解

 
 
Byte 基本数据类型byte  的包装类
Byte 类型的对象包含一个 byte类型的字段 
 
 
image_5bb0643f_65ee
 
 
 

属性简介

image
 

构造方法

Byte的构造方法也是有两种
能够经过基本类型byte   或者字符串形式
Byte(byte value) image_5bb0643f_4fd9
Byte(String s) image_5bb0643f_5c14
 
 

经常使用方法

比较

 
static int compare(byte x, byte y) 静态方法
x<y   小于0
x=y   等于0
x>y   大于0
image_5bb0643f_7da1
int compareTo(Byte anotherByte) 实例方法
调用静态方法处理两个对象内部value的值
image_5bb0643f_19ae
 

parseXXX系列

字符串解析 为 基本类型,
不须要对象,因此都是静态方法
image_5bb0643f_916
 
 
static byte parseByte(String s, int radix)
使用第二个参数指定的基数(进制),将字符串参数解析为有符号的整数
除了第一个字符能够是用来表示负值的 ASCII 减号 '-' ('\u002D’),加号'+' ('\u002B')  外
字符串中的字符必须都是指定基数的数字
static byte parseByte(String s)  static byte parseByte(String s, int radix)的十进制简化形式
image_5bb0643f_5f23
 

valueOf系列

把基本基本类型 包装为对象
用来建立得到对象,因此无需对象,全都是静态方法
image_5bb0643f_6362
 
VaueOf系列都有对应的缓存区, 缓存区范围内对象为同一个 
缓冲区为静态内部类中的数组 
image_5bb0643f_29e1
 
static Byte valueOf(byte b) 静态方法
读取缓存中的对象 由于byte的取值范围就是-128 ~ 127
因此全部对象都被缓存
image_5bb0643f_6962
static Byte valueOf(String s, int radix) 静态方法
借助于parseByte将字符转变为byte  而且返回Byte对象
image_5bb0643f_bd5
static Byte valueOf(String s) 静态方法
Byte valueOf(String s, int radix)的十进制简化形式

image_5bb0643f_73c8
 

decode

Byte也提供了decode方法
能够解析带有前缀的字符串
实际使用的是Integer的decode
而后将数值强转为byte
image_5bb0643f_7d6a
 

XXXValue系列

获取对象的某种基本类型的值
须要获取对象的因此必然所有都是实例方法
image_5bb0643f_2d75
强制类型转换的形式,将内部的  byte 值转换为指定的类型 
相似 Integer和Long 
Byte也有提供XXXValue系列方法,原理也跟他们相似
所有都是强转
byteValue()
shortValue()
intValue()
longValue()
floatValue()
doubleValue()
 

toString  toXXXString  系列

static String toString(byte b) 静态方法
image_5bb0643f_3901
String toString()  实例方法
image_5bb0643f_1fc8
static int toUnsignedInt(byte x) 静态方法
image_5bb0643f_79e0
static long toUnsignedLong(byte x)  静态方法
image_5bb0643f_3c
 

hashcode

static int hashCode(byte value) 静态方法
image_5bb0643f_2f70
int hashCode() 实例方法
同Integer和Long同样,调用的静态方法的形式
image_5bb0643f_1a69
 

equals(Object)

 
重写了equals方法
内部比较的是对象的值
image_5bb0643f_5f75
 
 
能够看得出来,Byte中的方法相对于Integer和Long少了不少
并且有些仍是借助于Integer中的方法
相关文章
相关标签/搜索