Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Byte

public final class Byte
extends Number implements Comparable<Byte>

java.lang.Object
   ↳ java.lang.Number
     ↳ java.lang.Byte


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.

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, 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.

Inherited methods

From class java.lang.Number
From class java.lang.Object
From interface java.lang.Comparable

Constants

MAX_VALUE

Added in API level 1
byte MAX_VALUE

The maximum Byte value, 27-1.

Constant Value: 127 (0x0000007f)

MIN_VALUE

Added in API level 1
byte MIN_VALUE

The minimum Byte value, -27.

Constant Value: -128 (0xffffff80)

SIZE

Added in API level 1
int SIZE

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

Constant Value: 8 (0x00000008)

Fields

TYPE

Added in API level 1
Class<Byte> TYPE

The Class object that represents the primitive type byte.

Public constructors

Byte

Added in API level 1
Byte (byte value)

Constructs a new Byte with the specified primitive byte value.

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

Byte

Added in API level 1
Byte (String string)

Constructs a new Byte from the specified string.

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

See also:

Public methods

byteValue

Added in API level 1
byte byteValue ()

Gets the primitive value of this byte.

Returns
byte this object's primitive value.

compare

Added in API level 19
int compare (byte lhs, 
                byte rhs)

Compares two byte values.

Parameters
lhs byte
rhs byte
Returns
int 0 if lhs = rhs, less than 0 if lhs < rhs, and greater than 0 if lhs > rhs.

compareTo

Added in API level 1
int compareTo (Byte object)

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

Parameters
object Byte: the byte object to compare this object to.
Returns
int 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:

decode

Added in API level 1
Byte decode (String string)

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 String: a string representation of a single byte value.
Returns
Byte a Byte containing the value represented by string.
Throws
NumberFormatException if string cannot be parsed as a byte value.

doubleValue

Added in API level 1
double doubleValue ()

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

Returns
double the primitive double value of this object.

equals

Added in API level 1
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 of Byte and have the same byte value as this object.

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

floatValue

Added in API level 1
float floatValue ()

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

Returns
float the primitive float value of this object.

hashCode

Added in API level 1
int hashCode ()

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
int this object's hash code.

intValue

Added in API level 1
int intValue ()

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

Returns
int the primitive int value of this object.

longValue

Added in API level 1
long longValue ()

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

Returns
long the primitive long value of this object.

parseByte

Added in API level 1
byte parseByte (String string, 
                int radix)

Parses the specified string as a signed byte value using the specified radix. The ASCII character - ('-') is recognized as the minus sign.

Parameters
string String: the string representation of a single byte value.
radix int: the radix to use when parsing.
Returns
byte 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.

parseByte

Added in API level 1
byte parseByte (String string)

Parses the specified string as a signed decimal byte value. The ASCII character - ('-') is recognized as the minus sign.

Parameters
string String: the string representation of a single byte value.
Returns
byte the primitive byte value represented by string.
Throws
NumberFormatException if string can not be parsed as a byte value.

shortValue

Added in API level 1
short shortValue ()

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

Returns
short the primitive short value of this object.

toString

Added in API level 1
String toString (byte value)

Returns a string containing a concise, human-readable description of the specified byte value.

Parameters
value byte: the byte to convert to a string.
Returns
String a printable representation of value.

toString

Added in API level 1
String toString ()

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
String a printable representation of this object.

valueOf

Added in API level 1
Byte valueOf (String string)

Parses the specified string as a signed decimal byte value.

Parameters
string String: the string representation of a single byte value.
Returns
Byte a Byte instance containing the byte value represented by string.
Throws
NumberFormatException if string can not be parsed as a byte value.

See also:

valueOf

Added in API level 1
Byte valueOf (String string, 
                int radix)

Parses the specified string as a signed byte value using the specified radix.

Parameters
string String: the string representation of a single byte value.
radix int: the radix to use when parsing.
Returns
Byte 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.

See also:

valueOf

Added in API level 1
Byte valueOf (byte b)

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 byte: the byte value to store in the instance.
Returns
Byte a Byte instance containing b.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.