FileDocCategorySizeDatePackage
Byte.javaAPI DocAndroid 1.5 API10565Wed May 06 22:41:04 BST 2009java.lang

Byte

public final class Byte extends Number implements Comparable
The wrapper for the primitive type {@code byte}.
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
private final byte
value
The value which the receiver represents.
public static final byte
MAX_VALUE
The maximum {@code Byte} value, 27-1.
public static final byte
MIN_VALUE
The minimum {@code Byte} value, -27.
public static final int
SIZE
The number of bits needed to represent a {@code Byte} value in two's complement form.
public static final Class
TYPE
The {@link Class} object that represents the primitive type {@code byte}.
private static final Byte[]
CACHE
A cache of instances used by {@link #valueOf(byte)} and auto-boxing.
Constructors Summary
public Byte(byte value)
Constructs a new {@code Byte} with the specified primitive byte value.

param
value the primitive byte value to store in the new instance.
since
Android 1.0


                                               
       
        this.value = value;
    
public Byte(String string)
Constructs a new {@code Byte} from the specified string.

param
string the string representation of a single byte value.
throws
NumberFormatException if {@code string} can not be decoded into a byte value.
see
#parseByte(String)
since
Android 1.0

        this(parseByte(string));
    
Methods Summary
public bytebyteValue()
Gets the primitive value of this byte.

return
this object's primitive value.
since
Android 1.0

        return value;
    
public intcompareTo(java.lang.Byte object)
Compares this object to the specified byte object to determine their relative order.

param
object the byte object to compare this object to.
return
a negative value if the value of this byte is less than the value of {@code object}; 0 if the value of this byte and the value of {@code object} are equal; a positive value if the value of this byte is greater than the value of {@code object}.
see
java.lang.Comparable
since
Android 1.0

        return value > object.value ? 1 : (value < object.value ? -1 : 0);
    
public static java.lang.Bytedecode(java.lang.String string)
Parses the specified string and returns a {@code 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.

param
string a string representation of a single byte value.
return
a {@code Byte} containing the value represented by {@code string}.
throws
NumberFormatException if {@code string} can not be parsed as a byte value.
since
Android 1.0

        int intValue = Integer.decode(string).intValue();
        byte result = (byte) intValue;
        if (result == intValue) {
            return valueOf(result);
        }
        throw new NumberFormatException();
    
public doubledoubleValue()

        return value;
    
public booleanequals(java.lang.Object object)
Compares this object with the specified object and indicates if they are equal. In order to be equal, {@code object} must be an instance of {@code Byte} and have the same byte value as this object.

param
object the object to compare this byte with.
return
{@code true} if the specified object is equal to this {@code Byte}; {@code false} otherwise.
since
Android 1.0

        return (object == this) || (object instanceof Byte)
                && (value == ((Byte) object).value);
    
public floatfloatValue()

        return value;
    
public inthashCode()

        return value;
    
public intintValue()

        return value;
    
public longlongValue()

        return value;
    
public static byteparseByte(java.lang.String string)
Parses the specified string as a signed decimal byte value. The ASCII character \u002d ('-') is recognized as the minus sign.

param
string the string representation of a single byte value.
return
the primitive byte value represented by {@code string}.
throws
NumberFormatException if {@code string} is {@code null}, has a length of zero or can not be parsed as a byte value.
since
Android 1.0

        int intValue = Integer.parseInt(string);
        byte result = (byte) intValue;
        if (result == intValue) {
            return result;
        }
        throw new NumberFormatException();
    
public static byteparseByte(java.lang.String string, int radix)
Parses the specified string as a signed byte value using the specified radix. The ASCII character \u002d ('-') is recognized as the minus sign.

param
string the string representation of a single byte value.
param
radix the radix to use when parsing.
return
the primitive byte value represented by {@code string} using {@code radix}.
throws
NumberFormatException if {@code string} is {@code null} or has a length of zero, {@code radix < Character.MIN_RADIX}, {@code radix > Character.MAX_RADIX}, or if {@code string} can not be parsed as a byte value.
since
Android 1.0

        int intValue = Integer.parseInt(string, radix);
        byte result = (byte) intValue;
        if (result == intValue) {
            return result;
        }
        throw new NumberFormatException();
    
public shortshortValue()

        return value;
    
public java.lang.StringtoString()

        return Integer.toString(value);
    
public static java.lang.StringtoString(byte value)
Returns a string containing a concise, human-readable description of the specified byte value.

param
value the byte to convert to a string.
return
a printable representation of {@code value}.
since
Android 1.0

        return Integer.toString(value);
    
public static java.lang.BytevalueOf(java.lang.String string)
Parses the specified string as a signed decimal byte value.

param
string the string representation of a single byte value.
return
a {@code Byte} instance containing the byte value represented by {@code string}.
throws
NumberFormatException if {@code string} is {@code null}, has a length of zero or can not be parsed as a byte value.
see
#parseByte(String)
since
Android 1.0

        return valueOf(parseByte(string));
    
public static java.lang.BytevalueOf(java.lang.String string, int radix)
Parses the specified string as a signed byte value using the specified radix.

param
string the string representation of a single byte value.
param
radix the radix to use when parsing.
return
a {@code Byte} instance containing the byte value represented by {@code string} using {@code radix}.
throws
NumberFormatException if {@code string} is {@code null} or has a length of zero, {@code radix < Character.MIN_RADIX}, {@code radix > Character.MAX_RADIX}, or if {@code string} can not be parsed as a byte value.
see
#parseByte(String, int)
since
Android 1.0

        return valueOf(parseByte(string, radix));
    
public static java.lang.BytevalueOf(byte b)
Returns a {@code Byte} instance for the specified byte value.

If it is not necessary to get a new {@code 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.

param
b the byte value to store in the instance.
return
a {@code Byte} instance containing {@code b}.
since
Android 1.0

        synchronized (CACHE) {
            int idx = b - MIN_VALUE;
            Byte result = CACHE[idx];
            return (result == null ? CACHE[idx] = new Byte(b) : result);
        }