Package java.lang
Class Byte
- java.lang.Object
-
- java.lang.Number
-
- java.lang.Byte
-
- All Implemented Interfaces:
Serializable
,Comparable<Byte>
,Modified
public final class Byte extends Number implements Comparable<Byte>, Modified
The wrapper for the primitive typebyte
.- Since:
- 1.1
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description byte
byteValue()
Gets the primitive value of this byte.static int
compare(byte lhs, byte rhs)
Compares twobyte
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 aByte
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.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 aByte
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.
-
-
-
Field Detail
-
MAX_VALUE
public static final byte MAX_VALUE
The maximumByte
value, 27-1.- See Also:
- Constant Field Values
-
MIN_VALUE
public static final byte MIN_VALUE
The minimumByte
value, -27.- See Also:
- Constant Field Values
-
SIZE
public static final int SIZE
The number of bits needed to represent aByte
value in two's complement form.- Since:
- 1.5
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Byte
public Byte(byte value)
Constructs a newByte
with the specified primitive byte value.- Parameters:
value
- the primitive byte value to store in the new instance.
-
Byte
public Byte(String string) throws NumberFormatException
Constructs a newByte
from the specified string.- Parameters:
string
- the string representation of a single byte value.- Throws:
NumberFormatException
- ifstring
cannot be parsed as a byte value.- See Also:
parseByte(String)
-
-
Method Detail
-
byteValue
public byte byteValue()
Gets the primitive value of this byte.
-
compareTo
public int compareTo(Byte object)
Compares this object to the specified byte object to determine their relative order.- Specified by:
compareTo
in interfaceComparable<Byte>
- Parameters:
object
- the byte object to compare this object to.- Returns:
- a negative value if the value of this byte is less than the value
of
object
; 0 if the value of this byte and the value ofobject
are equal; a positive value if the value of this byte is greater than the value ofobject
. - Since:
- 1.2
- See Also:
Comparable
-
compare
public static int compare(byte lhs, byte rhs)
Compares twobyte
values.- Parameters:
lhs
- First value.rhs
- Second value.- Returns:
- 0 if lhs = rhs, less than 0 if lhs < rhs, and greater than 0 if lhs > rhs.
- Since:
- 1.7
-
decode
public static Byte decode(String string) throws NumberFormatException
Parses the specified string and returns aByte
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.- Parameters:
string
- a string representation of a single byte value.- Returns:
- a
Byte
containing the value represented bystring
. - Throws:
NumberFormatException
- ifstring
cannot be parsed as a byte value.
-
doubleValue
public double doubleValue()
Description copied from class:Number
Returns this object's value as a double. Might involve rounding.- Specified by:
doubleValue
in classNumber
- Returns:
- the primitive double value of this object.
-
equals
public boolean equals(Object object)
Compares this object with the specified object and indicates if they are equal. In order to be equal,object
must be an instance ofByte
and have the same byte value as this object.- Overrides:
equals
in classObject
- Parameters:
object
- the object to compare this byte with.- Returns:
true
if the specified object is equal to thisByte
;false
otherwise.- See Also:
Object.hashCode()
-
floatValue
public float floatValue()
Description copied from class:Number
Returns this object's value as a float. Might involve rounding.- Specified by:
floatValue
in classNumber
- Returns:
- the primitive float value of this object.
-
hashCode
public int hashCode()
Description copied from class:Object
Returns an integer hash code for this object. By contract, any two objects for whichObject.equals(java.lang.Object)
returnstrue
must return the same hash code value. This means that subclasses ofObject
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 ownhashCode
method.- Overrides:
hashCode
in classObject
- Returns:
- this object's hash code.
- See Also:
Object.equals(java.lang.Object)
-
intValue
public int intValue()
Description copied from class:Number
Returns this object's value as an int. Might involve rounding and/or truncating the value, so it fits into an int.
-
longValue
public long longValue()
Description copied from class:Number
Returns this object's value as a long. Might involve rounding and/or truncating the value, so it fits into a long.
-
parseByte
public static byte parseByte(String string) throws NumberFormatException
Parses the specified string as a signed decimal byte value. The ASCII character - ('-') is recognized as the minus sign.- Parameters:
string
- the string representation of a single byte value.- Returns:
- the primitive byte value represented by
string
. - Throws:
NumberFormatException
- ifstring
can not be parsed as a byte value.
-
parseByte
public static byte parseByte(String string, int radix) throws NumberFormatException
Parses the specified string as a signed byte value using the specified radix. The ASCII character - ('-') is recognized as the minus sign.- Parameters:
string
- the string representation of a single byte value.radix
- the radix to use when parsing.- Returns:
- the primitive byte value represented by
string
usingradix
. - Throws:
NumberFormatException
- ifstring
can not be parsed as a byte value, orradix < Character.MIN_RADIX || radix > Character.MAX_RADIX
.
-
shortValue
public short shortValue()
Description copied from class:Number
Returns this object's value as a short. Might involve rounding and/or truncating the value, so it fits into a short.- Overrides:
shortValue
in classNumber
- Returns:
- the primitive short value of this object.
-
toString
public String toString()
Description copied from class:Object
Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data.
-
toString
public static String toString(byte value)
Returns a string containing a concise, human-readable description of the specified byte value.- Parameters:
value
- the byte to convert to a string.- Returns:
- a printable representation of
value
.
-
valueOf
public static Byte valueOf(String string) throws NumberFormatException
Parses the specified string as a signed decimal byte value.- Parameters:
string
- the string representation of a single byte value.- Returns:
- a
Byte
instance containing the byte value represented bystring
. - Throws:
NumberFormatException
- ifstring
can not be parsed as a byte value.- See Also:
parseByte(String)
-
valueOf
public static Byte valueOf(String string, int radix) throws NumberFormatException
Parses the specified string as a signed byte value using the specified radix.- Parameters:
string
- the string representation of a single byte value.radix
- the radix to use when parsing.- Returns:
- a
Byte
instance containing the byte value represented bystring
usingradix
. - Throws:
NumberFormatException
- ifstring
can not be parsed as a byte value, orradix < Character.MIN_RADIX || radix > Character.MAX_RADIX
.- See Also:
parseByte(String, int)
-
valueOf
public static Byte valueOf(byte b)
Returns aByte
instance for the specified byte value.- Parameters:
b
- the byte value to store in the instance.- Returns:
- a
Byte
instance containingb
. - Since:
- 1.5
-
-