java.lang.Byte Class & Methods

The java.lang.Byte class wraps a value of primitive type byte in an object. An object of type Byte contains a single field whose type is byte. This class provides several utility methods like converting a byte to a String and a String to a byte, as well as other constants and methods useful when dealing with a byte.

Byte class implements Comparable Interface that’s help while sorting list of Objects on natural order.

See Also:

Constants

  • static byte MAX_VALUE :A constant holding the maximum value a byte can have, 27-1.
  • static byte MIN_VALUE :A constant holding the minimum value a byte can have, -27.
  • static int SIZE :The number of bits used to represent a byte value in two’s complement binary form.
  • static Class TYPE : The Class instance representing the primitive type byte.

Constructors

  • Byte(byte value):Constructs a newly allocated Byte object that represents the specified byte value.
  • Byte(String s) :Constructs a newly allocated Byte object that represents the byte value indicated by the String parameter.

Methods 

  • byte byteValue() :Returns the value of this Byte as a byte.
  • static int compare(byte x, byte y) :Compares two byte values numerically.
  • int compareTo(Byte anotherByte) :Compares two Byte objects numerically.
  • static Byte decode(String nm) :Decodes a String into a Byte.
  • double doubleValue() :Returns the value of this Byte as a double.
  • boolean equals(Object obj) :Compares this object to the specified object.
  • float floatValue() :Returns the value of this Byte as a float.
  • int hashCode() :Returns a hash code for this Byte; equal to the result of invoking intValue().
  • int intValue() :Returns the value of this Byte as an int.
  • long longValue() :Returns the value of this Byte as a long.
  • static byte parseByte(String s) :Parses the string argument as a signed decimal byte.
  • static byte parseByte(String s, int radix) :Parses the string argument as a signed byte in the radix specified by the second argument.
  • short shortValue() :Returns the value of this Byte as a short.
  • String toString() :Returns a String object representing this Byte’s value.
  • static String toString(byte b) :Returns a new String object representing the specified byte.
  • static Byte valueOf(byte b) :Returns a Byte instance representing the specified byte value.
  • static Byte valueOf(String s) :Returns a Byte object holding the value given by the specified String.
  • static Byte valueOf(String s, int radix) :Returns a Byte object holding the value extracted from the specified String when parsed with the radix given by the second argument.

Exceptions

References