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
Type | Field | Summary |
---|---|---|
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. |
static Class<Byte> | TYPE | The Class instance representing the primitive type byte. |
Byte's constructors
Constructor | Summary |
---|---|
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.
Return | Method | Summary |
---|---|---|
byte | byteValue() | Returns the value of this Byte as a byte. |
double | doubleValue() | Returns the value of this Byte as a double. |
float | floatValue() | Returns the value of this Byte as a float. |
int | intValue() | Returns the value of this Byte as an int. |
long | longValue() | Returns the value of this Byte as a long. |
short | shortValue() | 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.
Return | Method | Summary |
---|---|---|
static Byte | decode(String nm) | Decodes a String into a Byte. |
static byte | parseByte(String s) | Parses string argument to byte. |
static byte | parseByte(String s, int radix) | Parses string argument to byte in the radix. |
static Byte | valueOf(byte b) | Converts byte value to Byte. |
static Byte | valueOf(String s) | Converts string to byte. |
static Byte | valueOf(String s, int radix) | Converts string to byte in radix. |
toString method is used to convert byte value to string value.
Return | Method | Summary |
---|---|---|
static String | toString(byte b) | Returns a new String object representing the specified byte. |
String | toString() | Returns a String object representing this Byte's value. |
To compare two byte values from two different Byte objects we use compareTo method:
Return | Method | Summary |
---|---|---|
int | compareTo(Byte anotherByte) | Compares two Byte objects numerically. |
boolean | equals(Object obj) | Compares this object to the specified object. |
To get the hash code for a Byte object, use hashCode method:
Return | Method | Summary |
---|---|---|
int | hashCode() | 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. |