Byte class

The Byte class wraps a value of primitive type byte in an object.

Byte class provides several methods for converting a byte to a String and a String to a byte.

The declaration of Byte class is:


public final class Byte
extends Number
implements Comparable<Byte>

Byte's constant values

TypeFieldSummary
static byteMAX_VALUEA constant holding the maximum value a byte can have, 27-1.
static byteMIN_VALUEA constant holding the minimum value a byte can have, -27.
static intSIZEThe number of bits used to represent a byte value.
static Class<Byte>TYPEThe Class instance representing the primitive type byte.

Byte's constructors

ConstructorSummary
Byte(byte value)Creates a Byte object for byte value.
Byte(String s)Creates a Byte object for the byte value indicated by the String parameter.

The following table shows the methods we can use to convert a Byte object to primitive byte value, double value, float value, int value, long value and short value.

ReturnMethodSummary
bytebyteValue()Returns the value of this Byte as a byte.
doubledoubleValue()Returns the value of this Byte as a double.
floatfloatValue()Returns the value of this Byte as a float.
intintValue()Returns the value of this Byte as an int.
longlongValue()Returns the value of this Byte as a long.
shortshortValue()Returns the value of this Byte as a short.

The table below lists the methods which convert string or byte value to byte value or Byte object.

ReturnMethodSummary
static Bytedecode(String nm)Decodes a String into a Byte.
static byteparseByte(String s)Parses string argument to byte.
static byteparseByte(String s, int radix)Parses string argument to byte in the radix.
static BytevalueOf(byte b)Converts byte value to Byte.
static BytevalueOf(String s)Converts string to byte.
static BytevalueOf(String s, int radix)Converts string to byte in radix.

toString method is used to convert byte value to string value.

ReturnMethodSummary
static StringtoString(byte b)Returns a new String object representing the specified byte.
StringtoString()Returns a String object representing this Byte's value.

To compare two byte values from two different Byte objects we use compareTo method:

ReturnMethodSummary
intcompareTo(Byte anotherByte)Compares two Byte objects numerically.
booleanequals(Object obj)Compares this object to the specified object.

To get the hash code for a Byte object, use hashCode method:

ReturnMethodSummary
inthashCode()Returns a hash code for this Byte.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.