public final class Byte extends Number implements Comparable<Byte>
byte.| Modifier and Type | Field and Description |
|---|---|
static byte |
MAX_VALUE
The maximum
Byte value, 27-1. |
static byte |
MIN_VALUE
The minimum
Byte value, -27. |
static int |
SIZE
The number of bits needed to represent a
Byte value in two's
complement form. |
static Class<Byte> |
TYPE
The
Class object that represents the primitive type byte. |
| Constructor and Description |
|---|
Byte(byte value)
Constructs a new
Byte with the specified primitive byte value. |
Byte(String string)
Constructs a new
Byte from the specified string. |
| Modifier and Type | Method and Description |
|---|---|
byte |
byteValue()
Gets the primitive value of this byte.
|
static int |
compare(byte lhs,
byte rhs)
Compares two
byte values. |
int |
compareTo(Byte object)
Compares this object to the specified byte object to determine their
relative order.
|
static Byte |
decode(String string)
Parses the specified string and returns a
Byte instance if the
string can be decoded into a single byte value. |
double |
doubleValue()
Returns this object's value as a double.
|
boolean |
equals(Object object)
Compares this object with the specified object and indicates if they are
equal.
|
float |
floatValue()
Returns this object's value as a float.
|
int |
hashCode()
Returns an integer hash code for this object.
|
int |
intValue()
Returns this object's value as an int.
|
long |
longValue()
Returns this object's value as a long.
|
static byte |
parseByte(String string)
Parses the specified string as a signed decimal byte value.
|
static byte |
parseByte(String string,
int radix)
Parses the specified string as a signed byte value using the specified
radix.
|
short |
shortValue()
Returns this object's value as a short.
|
static String |
toHexString(byte b,
boolean upperCase)
Returns a two-digit hex string.
|
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
static String |
toString(byte value)
Returns a string containing a concise, human-readable description of the
specified byte value.
|
static Byte |
valueOf(byte b)
Returns a
Byte instance for the specified byte value. |
static Byte |
valueOf(String string)
Parses the specified string as a signed decimal byte value.
|
static Byte |
valueOf(String string,
int radix)
Parses the specified string as a signed byte value using the specified
radix.
|
public static final byte MAX_VALUE
Byte value, 27-1.public static final byte MIN_VALUE
Byte value, -27.public static final int SIZE
Byte value in two's
complement form.public Byte(byte value)
Byte with the specified primitive byte value.value - the primitive byte value to store in the new instance.public Byte(String string) throws NumberFormatException
Byte from the specified string.string - the string representation of a single byte value.NumberFormatException - if string cannot be parsed as a byte value.parseByte(String)public byte byteValue()
public int compareTo(Byte object)
compareTo in interface Comparable<Byte>object - the byte object to compare this object to.object; 0 if the value of this byte and the value of
object are equal; a positive value if the value of this
byte is greater than the value of object.Comparablepublic static int compare(byte lhs,
byte rhs)
byte values.public static Byte decode(String string) throws NumberFormatException
Byte instance if the
string can be decoded into a single byte value. The string may be an
optional minus sign "-" followed by a hexadecimal ("0x..." or "#..."),
octal ("0..."), or decimal ("...") representation of a byte.string - a string representation of a single byte value.Byte containing the value represented by string.NumberFormatException - if string cannot be parsed as a byte value.public double doubleValue()
NumberdoubleValue in class Numberpublic boolean equals(Object object)
object must be an instance of
Byte and have the same byte value as this object.equals in class Objectobject - the object to compare this byte with.true if the specified object is equal to this
Byte; false otherwise.Object.hashCode()public float floatValue()
NumberfloatValue in class Numberpublic int hashCode()
ObjectObject.equals(java.lang.Object) returns true must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode method
if you intend implementing your own hashCode method.
hashCode in class ObjectObject.equals(java.lang.Object)public int intValue()
Numberpublic long longValue()
Numberpublic static byte parseByte(String string) throws NumberFormatException
string - the string representation of a single byte value.string.NumberFormatException - if string can not be parsed as a byte value.public static byte parseByte(String string, int radix) throws NumberFormatException
string - the string representation of a single byte value.radix - the radix to use when parsing.string using
radix.NumberFormatException - if string can not be parsed as a byte value, or
radix < Character.MIN_RADIX ||
radix > Character.MAX_RADIX.public short shortValue()
NumbershortValue in class Numberpublic String toString()
ObjectgetClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString method
if you intend implementing your own toString method.
public static String toHexString(byte b, boolean upperCase)
public static String toString(byte value)
value - the byte to convert to a string.value.public static Byte valueOf(String string) throws NumberFormatException
string - the string representation of a single byte value.Byte instance containing the byte value represented by
string.NumberFormatException - if string can not be parsed as a byte value.parseByte(String)public static Byte valueOf(String string, int radix) throws NumberFormatException
string - the string representation of a single byte value.radix - the radix to use when parsing.Byte instance containing the byte value represented by
string using radix.NumberFormatException - if string can not be parsed as a byte value, or
radix < Character.MIN_RADIX ||
radix > Character.MAX_RADIX.parseByte(String, int)public static Byte valueOf(byte b)
Byte instance for the specified byte value.
If it is not necessary to get a new Byte instance, it is
recommended to use this method instead of the constructor, since it
maintains a cache of instances which may result in better performance.
b - the byte value to store in the instance.Byte instance containing b.