public final classByteextendsNumberimplementsComparable<Byte>
Byte class wraps a value of primitive typebyte in an object. An object of typeByte contains a single field whose type isbyte.In addition, this class provides several methods for converting abyte to aString and aString to abyte, as well as other constants and methods useful when dealing with abyte.
Number,Serialized Form| Modifier and Type | Field | Description |
|---|---|---|
static int | BYTES | The number of bytes used to represent a byte value in two's complement binary form. |
static byte | MAX_VALUE | A constant holding the maximum value a byte can have, 27-1. |
static byte | MIN_VALUE | A constant holding the minimum value a byte can have, -27. |
static int | SIZE | The number of bits used to represent a byte value in two's complement binary form. |
staticClass<Byte> | TYPE | The Class instance representing the primitive typebyte. |
| Constructor | Description |
|---|---|
Byte(byte value) | Constructs a newly allocated Byte object that represents the specifiedbyte value. |
Byte(String s) | Constructs a newly allocated Byte object that represents thebyte value indicated by theString parameter. |
| Modifier and Type | Method | Description |
|---|---|---|
byte | byteValue() | Returns the value of this Byte as abyte. |
static int | compare(byte x, byte y) | Compares two byte values numerically. |
int | compareTo(Byte anotherByte) | Compares two Byte objects numerically. |
staticByte | decode(String nm) | Decodes a String into aByte. |
double | doubleValue() | Returns the value of this Byte as adouble after a widening primitive conversion. |
boolean | equals(Object obj) | Compares this object to the specified object. |
float | floatValue() | Returns the value of this Byte as afloat after a widening primitive conversion. |
int | hashCode() | Returns a hash code for this Byte; equal to the result of invokingintValue(). |
static int | hashCode(byte value) | Returns a hash code for a byte value; compatible withByte.hashCode(). |
int | intValue() | Returns the value of this Byte as anint after a widening primitive conversion. |
long | longValue() | Returns the value of this Byte as along after a widening primitive conversion. |
static byte | parseByte(String s) | Parses the string argument as a signed decimal byte. |
static byte | parseByte(String s, int radix) | Parses the string argument as a signed byte in the radix specified by the second argument. |
short | shortValue() | Returns the value of this Byte as ashort after a widening primitive conversion. |
String | toString() | Returns a String object representing thisByte's value. |
staticString | toString(byte b) | Returns a new String object representing the specifiedbyte. |
static int | toUnsignedInt(byte x) | Converts the argument to an int by an unsigned conversion. |
static long | toUnsignedLong(byte x) | Converts the argument to a long by an unsigned conversion. |
staticByte | valueOf(byte b) | Returns a Byte instance representing the specifiedbyte value. |
staticByte | valueOf(String s) | Returns a Byte object holding the value given by the specifiedString. |
staticByte | valueOf(String s, int radix) | Returns a Byte object holding the value extracted from the specifiedString when parsed with the radix given by the second argument. |
public static final byte MIN_VALUE
byte can have, -27.public static final byte MAX_VALUE
byte can have, 27-1.public static final int SIZE
byte value in two's complement binary form.public static final int BYTES
byte value in two's complement binary form.public Byte(byte value)
Byte object that represents the specifiedbyte value.value - the value to be represented by theByte.public Byte(String s) throwsNumberFormatException
Byte object that represents thebyte value indicated by theString parameter. The string is converted to abyte value in exactly the manner used by theparseByte method for radix 10.s - theString to be converted to aByteNumberFormatException - If theString does not contain a parsablebyte.parseByte(java.lang.String, int)public static String toString(byte b)
String object representing the specifiedbyte. The radix is assumed to be 10.b - thebyte to be convertedbyteInteger.toString(int)public static Byte valueOf(byte b)
Byte instance representing the specifiedbyte value. If a newByte instance is not required, this method should generally be used in preference to the constructorByte(byte), as this method is likely to yield significantly better space and time performance since all byte values are cached.b - a byte value.Byte instance representingb.public static byte parseByte(String s, int radix) throwsNumberFormatException
byte in the radix specified by the second argument. The characters in the string must all be digits, of the specified radix (as determined by whetherCharacter.digit(char, int) returns a nonnegative value) except that the first character may be an ASCII minus sign'-' ('\u002D') to indicate a negative value or an ASCII plus sign'+' ('\u002B') to indicate a positive value. The resultingbyte value is returned.An exception of typeNumberFormatException is thrown if any of the following situations occurs:
null or is a string of length zero.Character.MIN_RADIX or larger thanCharacter.MAX_RADIX.'-' ('\u002D') or plus sign'+' ('\u002B') provided that the string is longer than length 1.byte.s - theString containing thebyte representation to be parsedradix - the radix to be used while parsingsbyte value represented by the string argument in the specified radixNumberFormatException - If the string does not contain a parsablebyte.public static byte parseByte(String s) throwsNumberFormatException
byte. The characters in the string must all be decimal digits, except that the first character may be an ASCII minus sign'-' ('\u002D') to indicate a negative value or an ASCII plus sign'+' ('\u002B') to indicate a positive value. The resultingbyte value is returned, exactly as if the argument and the radix 10 were given as arguments to theparseByte(java.lang.String, int) method.s - aString containing thebyte representation to be parsedbyte value represented by the argument in decimalNumberFormatException - if the string does not contain a parsablebyte.public static Byte valueOf(String s, int radix) throwsNumberFormatException
Byte object holding the value extracted from the specifiedString when parsed with the radix given by the second argument. The first argument is interpreted as representing a signedbyte in the radix specified by the second argument, exactly as if the argument were given to theparseByte(java.lang.String, int) method. The result is aByte object that represents thebyte value specified by the string. In other words, this method returns aByte object equal to the value of:
new Byte(Byte.parseByte(s, radix))s - the string to be parsedradix - the radix to be used in interpretingsByte object holding the value represented by the string argument in the specified radix.NumberFormatException - If theString does not contain a parsablebyte.public static Byte valueOf(String s) throwsNumberFormatException
Byte object holding the value given by the specifiedString. The argument is interpreted as representing a signed decimalbyte, exactly as if the argument were given to theparseByte(java.lang.String) method. The result is aByte object that represents thebyte value specified by the string. In other words, this method returns aByte object equal to the value of:
new Byte(Byte.parseByte(s))s - the string to be parsedByte object holding the value represented by the string argumentNumberFormatException - If theString does not contain a parsablebyte.public static Byte decode(String nm) throwsNumberFormatException
String into aByte. Accepts decimal, hexadecimal, and octal numbers given by the following grammar:DecimalNumeral,HexDigits, andOctalDigits are as defined in section 3.10.1 ofThe Java™ Language Specification, except that underscores are not accepted between digits.
- DecodableString:
- Signopt DecimalNumeral
- Signopt
0xHexDigits- Signopt
0XHexDigits- Signopt
#HexDigits- Signopt
0OctalDigits- Sign:
-+
The sequence of characters following an optional sign and/or radix specifier ("0x", "0X", "#", or leading zero) is parsed as by theByte.parseByte method with the indicated radix (10, 16, or 8). This sequence of characters must represent a positive value or aNumberFormatException will be thrown. The result is negated if first character of the specifiedString is the minus sign. No whitespace characters are permitted in theString.
nm - theString to decode.Byte object holding thebyte value represented bynmNumberFormatException - if theString does not contain a parsablebyte.parseByte(java.lang.String, int)public byte byteValue()
Byte as abyte.public short shortValue()
Byte as ashort after a widening primitive conversion.shortValue in class Numbershort.public int intValue()
Byte as anint after a widening primitive conversion.public long longValue()
Byte as along after a widening primitive conversion.public float floatValue()
Byte as afloat after a widening primitive conversion.floatValue in class Numberfloat.public double doubleValue()
Byte as adouble after a widening primitive conversion.doubleValue in class Numberdouble.public String toString()
String object representing thisByte's value. The value is converted to signed decimal representation and returned as a string, exactly as if thebyte value were given as an argument to thetoString(byte) method.public int hashCode()
Byte; equal to the result of invokingintValue().hashCode in class ObjectByteObject.equals(java.lang.Object),System.identityHashCode(java.lang.Object)public static int hashCode(byte value)
byte value; compatible withByte.hashCode().value - the value to hashbyte value.public boolean equals(Object obj)
true if and only if the argument is notnull and is aByte object that contains the samebyte value as this object.equals in class Objectobj - the object to compare withtrue if the objects are the same;false otherwise.Object.hashCode(),HashMappublic int compareTo(Byte anotherByte)
Byte objects numerically.compareTo in interface Comparable<Byte>anotherByte - theByte to be compared.0 if thisByte is equal to the argumentByte; a value less than0 if thisByte is numerically less than the argumentByte; and a value greater than0 if thisByte is numerically greater than the argumentByte (signed comparison).public static int compare(byte x, byte y)
byte values numerically. The value returned is identical to what would be returned by:Byte.valueOf(x).compareTo(Byte.valueOf(y))
x - the firstbyte to comparey - the secondbyte to compare0 ifx == y; a value less than0 ifx < y; and a value greater than0 ifx > ypublic static int toUnsignedInt(byte x)
int by an unsigned conversion. In an unsigned conversion to anint, the high-order 24 bits of theint are zero and the low-order 8 bits are equal to the bits of thebyte argument. Consequently, zero and positivebyte values are mapped to a numerically equalint value and negativebyte values are mapped to anint value equal to the input plus 28.x - the value to convert to an unsignedintint by an unsigned conversionpublic static long toUnsignedLong(byte x)
long by an unsigned conversion. In an unsigned conversion to along, the high-order 56 bits of thelong are zero and the low-order 8 bits are equal to the bits of thebyte argument. Consequently, zero and positivebyte values are mapped to a numerically equallong value and negativebyte values are mapped to along value equal to the input plus 28.x - the value to convert to an unsignedlonglong by an unsigned conversion