Package java.lang
Class Byte
java.lang.Object
java.lang.Number
java.lang.Byte
- All Implemented Interfaces:
Serializable,Comparable<Byte>
public final class Byte extends Number implements Comparable<Byte>
The wrapper for the primitive type
byte.- Since:
- 1.1
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description static byteMAX_VALUEThe maximumBytevalue, 27-1.static byteMIN_VALUEThe minimumBytevalue, -27.static intSIZEThe number of bits needed to represent aBytevalue in two's complement form.static Class<Byte>TYPETheClassobject that represents the primitive typebyte. -
Constructor Summary
-
Method Summary
Modifier and Type Method Description bytebyteValue()Gets the primitive value of this byte.static intcompare(byte lhs, byte rhs)Compares twobytevalues.intcompareTo(Byte object)Compares this object to the specified byte object to determine their relative order.static Bytedecode(String string)Parses the specified string and returns aByteinstance if the string can be decoded into a single byte value.doubledoubleValue()Returns this object's value as a double.booleanequals(Object object)Compares this object with the specified object and indicates if they are equal.floatfloatValue()Returns this object's value as a float.inthashCode()Returns an integer hash code for this object.intintValue()Returns this object's value as an int.longlongValue()Returns this object's value as a long.static byteparseByte(String string)Parses the specified string as a signed decimal byte value.static byteparseByte(String string, int radix)Parses the specified string as a signed byte value using the specified radix.shortshortValue()Returns this object's value as a short.static StringtoHexString(byte b, boolean upperCase)Returns a two-digit hex string.StringtoString()Returns a string containing a concise, human-readable description of this object.static StringtoString(byte value)Returns a string containing a concise, human-readable description of the specified byte value.static BytevalueOf(byte b)Returns aByteinstance for the specified byte value.static BytevalueOf(String string)Parses the specified string as a signed decimal byte value.static BytevalueOf(String string, int radix)Parses the specified string as a signed byte value using the specified radix.
-
Field Details
-
MAX_VALUE
public static final byte MAX_VALUEThe maximumBytevalue, 27-1.- See Also:
- Constant Field Values
-
MIN_VALUE
public static final byte MIN_VALUEThe minimumBytevalue, -27.- See Also:
- Constant Field Values
-
SIZE
public static final int SIZEThe number of bits needed to represent aBytevalue in two's complement form.- Since:
- 1.5
- See Also:
- Constant Field Values
-
TYPE
TheClassobject that represents the primitive typebyte.
-
-
Constructor Details
-
Byte
public Byte(byte value)Constructs a newBytewith the specified primitive byte value.- Parameters:
value- the primitive byte value to store in the new instance.
-
Byte
Constructs a newBytefrom the specified string.- Parameters:
string- the string representation of a single byte value.- Throws:
NumberFormatException- ifstringcannot be parsed as a byte value.- See Also:
parseByte(String)
-
-
Method Details
-
byteValue
public byte byteValue()Gets the primitive value of this byte. -
compareTo
Compares this object to the specified byte object to determine their relative order.- Specified by:
compareToin 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 ofobjectare 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 twobytevalues.- Returns:
- 0 if lhs = rhs, less than 0 if lhs < rhs, and greater than 0 if lhs > rhs.
- Since:
- 1.7
-
decode
Parses the specified string and returns aByteinstance 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
Bytecontaining the value represented bystring. - Throws:
NumberFormatException- ifstringcannot be parsed as a byte value.
-
doubleValue
public double doubleValue()Description copied from class:NumberReturns this object's value as a double. Might involve rounding.- Specified by:
doubleValuein classNumber- Returns:
- the primitive double value of this object.
-
equals
Compares this object with the specified object and indicates if they are equal. In order to be equal,objectmust be an instance ofByteand have the same byte value as this object.- Overrides:
equalsin classObject- Parameters:
object- the object to compare this byte with.- Returns:
trueif the specified object is equal to thisByte;falseotherwise.- See Also:
Object.hashCode()
-
floatValue
public float floatValue()Description copied from class:NumberReturns this object's value as a float. Might involve rounding.- Specified by:
floatValuein classNumber- Returns:
- the primitive float value of this object.
-
hashCode
public int hashCode()Description copied from class:ObjectReturns an integer hash code for this object. By contract, any two objects for whichObject.equals(java.lang.Object)returnstruemust return the same hash code value. This means that subclasses ofObjectusually 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
hashCodemethod if you intend implementing your ownhashCodemethod.- Overrides:
hashCodein classObject- Returns:
- this object's hash code.
- See Also:
Object.equals(java.lang.Object)
-
intValue
public int intValue()Description copied from class:NumberReturns 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:NumberReturns this object's value as a long. Might involve rounding and/or truncating the value, so it fits into a long. -
parseByte
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- ifstringcan not be parsed as a byte value.
-
parseByte
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
stringusingradix. - Throws:
NumberFormatException- ifstringcan not be parsed as a byte value, orradix < Character.MIN_RADIX || radix > Character.MAX_RADIX.
-
shortValue
public short shortValue()Description copied from class:NumberReturns this object's value as a short. Might involve rounding and/or truncating the value, so it fits into a short.- Overrides:
shortValuein classNumber- Returns:
- the primitive short value of this object.
-
toString
Description copied from class:ObjectReturns 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. The default implementation is equivalent to the following expression:getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toStringmethod if you intend implementing your owntoStringmethod. -
toHexString
Returns a two-digit hex string. That is, -1 becomes "ff" or "FF" and 2 becomes "02". -
toString
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
Parses the specified string as a signed decimal byte value.- Parameters:
string- the string representation of a single byte value.- Returns:
- a
Byteinstance containing the byte value represented bystring. - Throws:
NumberFormatException- ifstringcan not be parsed as a byte value.- See Also:
parseByte(String)
-
valueOf
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
Byteinstance containing the byte value represented bystringusingradix. - Throws:
NumberFormatException- ifstringcan not be parsed as a byte value, orradix < Character.MIN_RADIX || radix > Character.MAX_RADIX.- See Also:
parseByte(String, int)
-
valueOf
Returns aByteinstance for the specified byte value.If it is not necessary to get a new
Byteinstance, it is recommended to use this method instead of the constructor, since it maintains a cache of instances which may result in better performance.- Parameters:
b- the byte value to store in the instance.- Returns:
- a
Byteinstance containingb. - Since:
- 1.5
-