public final class Byte
extends Number implements Comparable<Byte>
| java.lang.Object | ||
| java.lang.Number | ||
| java.lang.Byte | ||
Byte类将原始类型byte的值包装在对象中。 类型为Byte的对象包含类型为byte的单个字段。
此外,该类提供了几种将 byte转换为 String和 String转换为 byte ,以及处理 byte时有用的其他常量和方法。
也可以看看:
常量(Constants) |
|
|---|---|
int |
BYTES 用于以二进制补码形式表示 |
byte |
MAX_VALUE 一个保持最大值的常量 |
byte |
MIN_VALUE 一个常数保持最小值a |
int |
SIZE 以二进制补码形式表示 |
Fields |
|
|---|---|
public static final Class<Byte> |
TYPE 表示原始类型 |
Public constructors |
|
|---|---|
Byte(byte value) 构造一个新分配的 |
|
Byte(String s) 构造一个新分配 |
|
公共方法(Public methods) |
|
|---|---|
byte |
byteValue() 返回此值 |
static int |
compare(byte x, byte y) 以数字方式比较两个 |
int |
compareTo(Byte anotherByte) 以数字方式比较两个 |
static Byte |
decode(String nm) 将 |
double |
doubleValue() 返回此值 |
boolean |
equals(Object obj) 将此对象与指定的对象进行比较。 |
float |
floatValue() 返回此值 |
int |
hashCode() 返回此 |
static int |
hashCode(byte value) 返回 |
int |
intValue() 返回此值 |
long |
longValue() 返回此值 |
static byte |
parseByte(String s) 将字符串参数解析为带符号的十进制数 |
static byte |
parseByte(String s, int radix) 将字符串参数解析为由第二个参数指定的基数中的带符号的 |
short |
shortValue() 返回此值 |
String |
toString() 返回代表此 |
static String |
toString(byte b) 返回一个新 |
static Byte |
valueOf(String s) 返回保存由指定的 |
static Byte |
valueOf(String s, int radix) 返回 |
static Byte |
valueOf(byte b) 返回表示指定的 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Number
|
|
java.lang.Object
|
|
java.lang.Comparable
|
|
Byte (byte value)
构造一个新分配的 Byte对象,该对象表示指定的 byte值。
| 参数(Parameters) | |
|---|---|
value |
byte: the value to be represented by the Byte. |
Byte (String s)
构造一个新分配的Byte对象,该对象表示由String参数指示的byte值。 该字符串parseByte方法用于基数10的方式完全转换为byte值。
| 参数(Parameters) | |
|---|---|
s |
String: the String to be converted to a Byte |
| 抛出异常(Throws) | |
|---|---|
NumberFormatException |
If the String does not contain a parsable byte. |
byte byteValue ()
返回此值 Byte为 byte 。
| 返回(Returns) | |
|---|---|
byte |
the numeric value represented by this object after conversion to type byte. |
int compare (byte x,
byte y)
以数字方式比较两个byte值。 返回的值与以下内容返回的值相同:
Byte.valueOf(x).compareTo(Byte.valueOf(y))
| 参数(Parameters) | |
|---|---|
x |
byte: the first byte to compare |
y |
byte: the second byte to compare |
| 返回(Returns) | |
|---|---|
int |
the value 0 if x == y; a value less than 0 if x < y; and a value greater than 0 if x > y |
int compareTo (Byte anotherByte)
以数字方式比较两个 Byte对象。
| 参数(Parameters) | |
|---|---|
anotherByte |
Byte: the Byte to be compared. |
| 返回(Returns) | |
|---|---|
int |
the value 0 if this Byte is equal to the argument Byte; a value less than 0 if this Byte is numerically less than the argument Byte; and a value greater than 0 if this Byte is numerically greater than the argument Byte (signed comparison). |
Byte decode (String nm)
将String解码为Byte 。 接受由以下语法给出的十进制,十六进制和八进制数字:
DecimalNumeral, HexDigits, and OctalDigits are as defined in section 3.10.1 of The JavaTM Language Specification, except that underscores are not accepted between digits.
- DecodableString:
- Signopt DecimalNumeral
- Signopt
0xHexDigits- Signopt
0XHexDigits- Signopt
#HexDigits- Signopt
0OctalDigits- Sign:
-+
可选符号和/或基数说明符(“ 0x ”,“ 0X ”,“ # ”或前导零)后面的字符序列按Byte.parseByte方法用指示的基数(10,16或8)进行解析。 这个字符序列必须表示一个正值, NumberFormatException将抛出一个NumberFormatException 。 如果指定的String第一个字符是负号,则结果将被否定。 String中不允许有空格字符。
| 参数(Parameters) | |
|---|---|
nm |
String: the String to decode. |
| 返回(Returns) | |
|---|---|
Byte |
a Byte object holding the byte value represented by nm |
| 抛出异常(Throws) | |
|---|---|
NumberFormatException |
if the String does not contain a parsable byte. |
double doubleValue ()
返回此值 Byte为 double 。
| 返回(Returns) | |
|---|---|
double |
the numeric value represented by this object after conversion to type double. |
boolean equals (Object obj)
将此对象与指定的对象进行比较。 当且仅当参数不是null并且是包含与此对象相同的byte值的Byte对象时,结果为true 。
| 参数(Parameters) | |
|---|---|
obj |
Object: the object to compare with |
| 返回(Returns) | |
|---|---|
boolean |
true if the objects are the same; false otherwise. |
float floatValue ()
返回此值 Byte为 float 。
| 返回(Returns) | |
|---|---|
float |
the numeric value represented by this object after conversion to type float. |
int hashCode ()
返回此Byte的哈希码; 等于调用intValue()的结果。
| 返回(Returns) | |
|---|---|
int |
a hash code value for this Byte |
int hashCode (byte value)
返回byte值的哈希码; 与Byte.hashCode()兼容。
| 参数(Parameters) | |
|---|---|
value |
byte: the value to hash |
| 返回(Returns) | |
|---|---|
int |
a hash code value for a byte value. |
int intValue ()
返回此值 Byte为 int 。
| 返回(Returns) | |
|---|---|
int |
the numeric value represented by this object after conversion to type int. |
long longValue ()
返回此值 Byte为 long 。
| 返回(Returns) | |
|---|---|
long |
the numeric value represented by this object after conversion to type long. |
byte parseByte (String s)
将字符串参数解析为带符号的十进制数byte 。 字符串中的字符必须全部为十进制数字,但第一个字符可能是ASCII减号'-' ( '\u002D' )以指示负值或ASCII加号'+' ( '\u002B' )以指示正值。 返回结果byte值,就好像将参数和基数10作为参数提供给parseByte(java.lang.String, int)方法一样。
| 参数(Parameters) | |
|---|---|
s |
String: a String containing the byte representation to be parsed |
| 返回(Returns) | |
|---|---|
byte |
the byte value represented by the argument in decimal |
| 抛出异常(Throws) | |
|---|---|
NumberFormatException |
if the string does not contain a parsable byte. |
byte parseByte (String s, int radix)
将字符串参数解析为由第二个参数指定的基数中的带符号的byte 。 除了第一个字符可能是ASCII减号'-' ( '\u002D' )以指示负值或ASCII加号外,字符串中的字符必须全部是指定基数的数字(由digit(char, int)是否返回非负值'\u002D' ) '+' ( '\u002B' )表示正值。 返回结果byte值。
如果发生以下任何情况,将引发 NumberFormatException类型的异常:
null or is a string of length zero. MIN_RADIX or larger than MAX_RADIX. '-' ('\u002D') or plus sign '+' ('\u002B') provided that the string is longer than length 1. byte. | 参数(Parameters) | |
|---|---|
s |
String: the String containing the byte representation to be parsed |
radix |
int: the radix to be used while parsing s |
| 返回(Returns) | |
|---|---|
byte |
the byte value represented by the string argument in the specified radix |
| 抛出异常(Throws) | |
|---|---|
NumberFormatException |
If the string does not contain a parsable byte. |
short shortValue ()
返回此值 Byte为 short 。
| 返回(Returns) | |
|---|---|
short |
the numeric value represented by this object after conversion to type short. |
String toString ()
返回表示此Byte的值的String对象。 该值将转换为带符号的十进制表示形式,并以字符串形式返回,就好像将byte值作为toString(byte)方法的参数。
| 返回(Returns) | |
|---|---|
String |
a string representation of the value of this object in base 10. |
String toString (byte b)
返回一个新String表示指定对象byte 。 基数假定为10。
| 参数(Parameters) | |
|---|---|
b |
byte: the byte to be converted |
| 返回(Returns) | |
|---|---|
String |
the string representation of the specified byte |
也可以看看:
Byte valueOf (String s)
返回保存由指定的String给出的值的Byte对象。 该参数被解释为代表一个有符号的十进制数byte ,就像参数被赋予parseByte(java.lang.String)方法一样。 结果是一个Byte对象,表示由该字符串指定的byte值。
换句话说,该方法返回一个 Byte对象,其值等于:
new Byte(Byte.parseByte(s))
| 参数(Parameters) | |
|---|---|
s |
String: the string to be parsed |
| 返回(Returns) | |
|---|---|
Byte |
a Byte object holding the value represented by the string argument |
| 抛出异常(Throws) | |
|---|---|
NumberFormatException |
If the String does not contain a parsable byte. |
Byte valueOf (String s, int radix)
返回一个Byte对象,该对象保存从第二个参数给出的基数进行分析时从指定的String提取的值。 第一个参数被解释为表示由第二个参数指定的基数中的带符号的byte ,就像参数被赋予parseByte(java.lang.String, int)方法一样。 结果是一个Byte对象,它表示由该字符串指定的byte值。
换句话说,该方法返回一个 Byte对象,其值等于:
new Byte(Byte.parseByte(s, radix))
| 参数(Parameters) | |
|---|---|
s |
String: the string to be parsed |
radix |
int: the radix to be used in interpreting s |
| 返回(Returns) | |
|---|---|
Byte |
a Byte object holding the value represented by the string argument in the specified radix. |
| 抛出异常(Throws) | |
|---|---|
NumberFormatException |
If the String does not contain a parsable byte. |
Byte valueOf (byte b)
返回表示指定的byte值的Byte实例。 如果不需要新的Byte实例,则通常应该优先使用此方法,而不是构造函数Byte(byte) ,因为此方法可能会产生显着更好的空间和时间性能,因为所有字节值都被缓存。
| 参数(Parameters) | |
|---|---|
b |
byte: a byte value. |
| 返回(Returns) | |
|---|---|
Byte |
a Byte instance representing b. |