Class Byte

All Implemented Interfaces:
Comparable<Byte>

public final class Byte extends Number implements Comparable<Byte>
The Byte class is the standard wrapper for byte values. Since: JDK1.1, CLDC 1.0
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The size of a byte in bytes.
    static final byte
    The maximum value a Byte can have.
    static final byte
    The minimum value a Byte can have.
    static final int
     
    static final Class<Byte>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Byte(byte value)
    Constructs a Byte object initialized to the specified byte value.
    Deprecated.
  • Method Summary

    Modifier and Type
    Method
    Description
    byte
    Returns the value of this Byte as a byte.
    static int
    compare(byte b1, byte b2)
     
    int
    Compares this object to the specified object to determine their relative order.
    static int
    compareUnsigned(byte x, byte y)
    Compares the two as unsigned values.
    static Byte
    Decodes a decimal, hexadecimal or octal byte, as Integer.decode.
    double
     
    boolean
    Compares this object to the specified object.
    float
     
    int
    Returns a hashcode for this Byte.
    static int
    hashCode(byte value)
    The value itself.
    int
     
    long
     
    static byte
    Assuming the specified String represents a byte, returns that byte's value.
    static byte
    parseByte(String s, int radix)
    Assuming the specified String represents a byte, returns that byte's value.
    Returns a String object representing this Byte's value.
    static String
    toString(byte b)
    The decimal string of b.
    static int
    toUnsignedInt(byte x)
    The value as an unsigned int.
    static long
    The value as an unsigned long.
    static Byte
    valueOf(byte i)
    Returns the object instance of i
    static Byte
    A Byte of parseByte(s).
    static Byte
    valueOf(String s, int radix)
    A Byte of parseByte(s, radix).

    Methods inherited from class Number

    shortValue

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • TYPE

      public static final Class<Byte> TYPE
    • SIZE

      public static final int SIZE
      See Also:
    • MAX_VALUE

      public static final byte MAX_VALUE
      The maximum value a Byte can have. See Also:Constant Field Values
      See Also:
    • MIN_VALUE

      public static final byte MIN_VALUE
      The minimum value a Byte can have. See Also:Constant Field Values
      See Also:
    • BYTES

      public static final int BYTES
      The size of a byte in bytes.
      See Also:
  • Constructor Details

  • Method Details

    • byteValue

      public byte byteValue()
      Returns the value of this Byte as a byte.
      Overrides:
      byteValue in class Number
    • equals

      public boolean equals(Object obj)
      Compares this object to the specified object.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Returns a hashcode for this Byte.
      Overrides:
      hashCode in class Object
    • parseByte

      public static byte parseByte(String s) throws NumberFormatException
      Assuming the specified String represents a byte, returns that byte's value. Throws an exception if the String cannot be parsed as a byte. The radix is assumed to be 10.
      Throws:
      NumberFormatException
    • parseByte

      public static byte parseByte(String s, int radix) throws NumberFormatException
      Assuming the specified String represents a byte, returns that byte's value. Throws an exception if the String cannot be parsed as a byte.
      Throws:
      NumberFormatException
    • toString

      public String toString()
      Returns a String object representing this Byte's value.
      Overrides:
      toString in class Object
    • valueOf

      public static Byte valueOf(byte i)

      Returns the object instance of i

      Parameters
      • i: the primitive
      Returns

      object instance

    • intValue

      public int intValue()
      Specified by:
      intValue in class Number
    • longValue

      public long longValue()
      Specified by:
      longValue in class Number
    • floatValue

      public float floatValue()
      Specified by:
      floatValue in class Number
    • doubleValue

      public double doubleValue()
      Specified by:
      doubleValue in class Number
    • compare

      public static int compare(byte b1, byte b2)
    • compareTo

      public int compareTo(Byte b)
      Description copied from interface: Comparable

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

      Parameters
      • another: the object to compare to this instance.
      Returns
      Specified by:
      compareTo in interface Comparable<Byte>
      Returns:

      a negative integer if this instance is less than another; a positive integer if this instance is greater than another; 0 if this instance has the same order as another.

      Throws
      • ClassCastException: @throws ClassCastException if another cannot be converted into something comparable to this instance.
    • toString

      public static String toString(byte b)
      The decimal string of b.
    • valueOf

      public static Byte valueOf(String s) throws NumberFormatException
      A Byte of parseByte(s).
      Throws:
      NumberFormatException
    • valueOf

      public static Byte valueOf(String s, int radix) throws NumberFormatException
      A Byte of parseByte(s, radix).
      Throws:
      NumberFormatException
    • decode

      public static Byte decode(String nm) throws NumberFormatException
      Decodes a decimal, hexadecimal or octal byte, as Integer.decode.
      Throws:
      NumberFormatException
    • hashCode

      public static int hashCode(byte value)
      The value itself.
    • compareUnsigned

      public static int compareUnsigned(byte x, byte y)
      Compares the two as unsigned values.
    • toUnsignedInt

      public static int toUnsignedInt(byte x)
      The value as an unsigned int.
    • toUnsignedLong

      public static long toUnsignedLong(byte x)
      The value as an unsigned long.