to top
Android APIs
public final class

Byte

extends Number
implements Comparable<T>
java.lang.Object
   ↳ java.lang.Number
     ↳ java.lang.Byte

Class Overview

The wrapper for the primitive type byte.

Summary

Constants
byte MAX_VALUE The maximum Byte value, 27-1.
byte MIN_VALUE The minimum Byte value, -27.
int SIZE The number of bits needed to represent a Byte value in two's complement form.
Fields
public static final Class<Byte> TYPE The Class object that represents the primitive type byte.
Public Constructors
Byte(byte value)
Constructs a new Byte with the specified primitive byte value.
Byte(String string)
Constructs a new Byte from the specified string.
Public Methods
byte byteValue()
Gets the primitive value of this byte.
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, int radix)
Parses the specified string as a signed byte value using the specified radix.
static byte parseByte(String string)
Parses the specified string as a signed decimal byte value.
short shortValue()
Returns this object's value as a short.
static String toString(byte value)
Returns a string containing a concise, human-readable description of the specified byte value.
String toString()
Returns a string containing a concise, human-readable description of this object.
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.
static Byte valueOf(byte b)
Returns a Byte instance for the specified byte value.
[Expand]
Inherited Methods
From class java.lang.Number
From class java.lang.Object
From interface java.lang.Comparable

Constants

public static final byte MAX_VALUE

Added in API level 1

The maximum Byte value, 27-1.

Constant Value: 127 (0x0000007f)

public static final byte MIN_VALUE

Added in API level 1

The minimum Byte value, -27.

Constant Value: -128 (0xffffff80)

public static final int SIZE

Added in API level 1

The number of bits needed to represent a Byte value in two's complement form.

Constant Value: 8 (0x00000008)

Fields

public static final Class<Byte> TYPE

Added in API level 1

The Class object that represents the primitive type byte.

Public Constructors

public Byte (byte value)

Added in API level 1

Constructs a new Byte with the specified primitive byte value.

Parameters
value the primitive byte value to store in the new instance.

public Byte (String string)

Added in API level 1

Constructs a new Byte from the specified string.

Parameters
string the string representation of a single byte value.
Throws
NumberFormatException if string cannot be parsed as a byte value.

Public Methods

public byte byteValue ()

Added in API level 1

Gets the primitive value of this byte.

Returns
  • this object's primitive value.

public int compareTo (Byte object)

Added in API level 1

Compares this object to the specified byte object to determine their relative order.

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 of object are equal; a positive value if the value of this byte is greater than the value of object.
See Also

public static Byte decode (String string)

Added in API level 1

Parses the specified string and returns a 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.

Parameters
string a string representation of a single byte value.
Returns
  • a Byte containing the value represented by string.
Throws
NumberFormatException if string cannot be parsed as a byte value.

public double doubleValue ()

Added in API level 1

Returns this object's value as a double. Might involve rounding.

Returns
  • the primitive double value of this object.

public boolean equals (Object object)

Added in API level 1

Compares this object with the specified object and indicates if they are equal. In order to be equal, object must be an instance of Byte and have the same byte value as this object.

Parameters
object the object to compare this byte with.
Returns
  • true if the specified object is equal to this Byte; false otherwise.

public float floatValue ()

Added in API level 1

Returns this object's value as a float. Might involve rounding.

Returns
  • the primitive float value of this object.

public int hashCode ()

Added in API level 1

Returns an integer hash code for this object. By contract, any two objects for which equals(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.

Returns
  • this object's hash code.

public int intValue ()

Added in API level 1

Returns this object's value as an int. Might involve rounding and/or truncating the value, so it fits into an int.

Returns
  • the primitive int value of this object.

public long longValue ()

Added in API level 1

Returns this object's value as a long. Might involve rounding and/or truncating the value, so it fits into a long.

Returns
  • the primitive long value of this object.

public static byte parseByte (String string, int radix)

Added in API level 1

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 using radix.
Throws
NumberFormatException if string can not be parsed as a byte value, or radix < Character.MIN_RADIX || radix > Character.MAX_RADIX.

public static byte parseByte (String string)

Added in API level 1

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 if string can not be parsed as a byte value.

public short shortValue ()

Added in API level 1

Returns this object's value as a short. Might involve rounding and/or truncating the value, so it fits into a short.

Returns
  • the primitive short value of this object.

public static String toString (byte value)

Added in API level 1

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.

public String toString ()

Added in API level 1

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. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.

public static Byte valueOf (String string)

Added in API level 1

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 by string.
Throws
NumberFormatException if string can not be parsed as a byte value.

public static Byte valueOf (String string, int radix)

Added in API level 1

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 by string using radix.
Throws
NumberFormatException if string can not be parsed as a byte value, or radix < Character.MIN_RADIX || radix > Character.MAX_RADIX.

public static Byte valueOf (byte b)

Added in API level 1

Returns a 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.

Parameters
b the byte value to store in the instance.
Returns
  • a Byte instance containing b.