Java Byte Class

Java.lang 包提供了一个 Byte 类,它包装了对象中原始类型字节的值。 Byte 类型的对象包含一个类型为 byte 的字段。

此外,该类还提供了几种将字节转换为 String 和将 String 转换为字节的方法,以及其他常量和方法处理字节时很有用。

类声明

java.lang.Byte 类的声明为:

public final class Byte
  extends Number
    implements Comparable<Byte> 

字段

序号字段和描述
1.static int BYTES
用于表示二进制补码二进制形式的字节值的字节数。
2.static byte MAX_VALUE
保存字节可以具有的最大值的常量,27-1。
3.static byte MIN_VALUE
保存字节可以具有的最小值的常量,-2 7
4.static int SIZE
用于表示二进制补码字节值的位数二进制形式。
5.static Class<Byte> TYPE
表示原始类型字节的 Class 实例。

java.lang.Byte 方法

java.lang.Byte 类有许多方法,如下所示:

成员方法

序号方法和描述
1.byte byteValue()
以字节形式返回此 Byte 的值。
2.static int compare(byte x,byte y)
以数字方式比较两个字节值。
3.int CompareTo(Byte anotherByte)
对两个 Byte 对象进行数值比较。
4.static Byte decode(String nm)
将字符串解码为字节。
5.double doubleValue()
在加宽基元转换后返回此 Byte 的双精度值。
6.boolean equals(Object obj)
将此对象与指定对象进行比较。
7.float floatValue()
在加宽基元转换后以浮点形式返回此 Byte 的值。
8.int hashCode()
返回该 Byte 的哈希码;等于调用 intValue() 的结果。
9.static int hashCode(byte value)
返回字节值的哈希码;与 Byte.hashCode() 兼容。
10。int intValue()
在加宽基元转换后,以 int 形式返回此 Byte 的值。
11。long longValue()
在加宽基元转换后返回此 Byte 的值作为 long。
12.static byte parseByte(String s )
将字符串参数解析为带符号的十进制字节。
13.static byte parseByte(String s, int radix)
将字符串参数解析为第二个参数指定的基数中的有符号字节。
14。short shortValue()
在加宽基元转换后返回该 Byte 的值作为短整型。
15。String toString()
返回表示此 Byte 值的 String 对象。
16。static String toString(byte b )
返回表示指定字节的新 String 对象。
17。static int toUnsignedInt(byte x)
通过无符号转换将参数转换为 int。
18。static long toUnsignedLong(byte x)
通过无符号转换将参数转换为 long。
19.static Byte valueOf(byte b )
返回表示指定字节值的 Byte 实例。
20。static Byte valueOf(String s )
返回一个 Byte 对象,其中包含指定 String 给出的值。
21。static Byte valueOf( String s, int radix)
返回一个 Byte 对象,该对象保存使用第二个参数给定的基数解析时从指定 String 中提取的值。

继承的方法

该类继承了以下类的方法:

  • java.lang.Object
  • java.lang.Number