站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > JDK 5 Documentation v1.2.2, Java 2 SDK 英文文档

Java(TM) 2 Platform, Standard Edition, v1.2.2 API Specification: Class Byte - JDK 5 Documentation v1.2.2, Java 2 SDK 英文文档

JavaTM 2 Platform
Standard Edition

java.lang
Class Byte

java.lang.Object
  |
  +--java.lang.Number
        |
        +--java.lang.Byte

public final class Byte
extends Number
implements Comparable

The Byte class is the standard wrapper for byte values.

Since:
JDK1.1
See Also:
Number, Serialized Form

Field Summary
static byte MAX_VALUE
          The maximum value a Byte can have.
static byte MIN_VALUE
          The minimum value a Byte can have.
static Class TYPE
          The Class object representing the primitive type byte.
 
Constructor Summary
Byte(byte value)
          Constructs a Byte object initialized to the specified byte value.
Byte(String s)
          Constructs a Byte object initialized to the value specified by the String parameter.
 
Method Summary
 byte byteValue()
          Returns the value of this Byte as a byte.
 int compareTo(Byte anotherByte)
          Compares two Bytes numerically.
 int compareTo(Object o)
          Compares this Byte to another Object.
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 hashcode for this Byte.
 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)
          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.
 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(String s)
          Assuming the specified String represents a byte, returns a new Byte object initialized to that value.
static Byte valueOf(String s, int radix)
          Assuming the specified String represents a byte, returns a new Byte object initialized to that value.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_VALUE

public static final byte MIN_VALUE
The minimum value a Byte can have.

MAX_VALUE

public static final byte MAX_VALUE
The maximum value a Byte can have.

TYPE

public static final Class TYPE
The Class object representing the primitive type byte.
Constructor Detail

Byte

public Byte(byte value)
Constructs a Byte object initialized to the specified byte value.
Parameters:
value - the initial value of the Byte

Byte

public Byte(String s)
     throws NumberFormatException
Constructs a Byte object initialized to the value specified by the String parameter. The radix is assumed to be 10.
Parameters:
s - the String to be converted to a Byte
Throws:
NumberFormatException - If the String does not contain a parsable byte.
Method Detail

toString

public static String toString(byte b)
Returns a new String object representing the specified Byte. The radix is assumed to be 10.
Parameters:
b - the byte to be converted

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.
Parameters:
s - the String containing the byte
Throws:
NumberFormatException - If the string does not contain a parsable byte.

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.
Parameters:
s - the String containing the byte
radix - the radix to be used
Throws:
NumberFormatException - If the String does not contain a parsable byte.

valueOf

public static Byte valueOf(String s,
                           int radix)
                    throws NumberFormatException
Assuming the specified String represents a byte, returns a new Byte object initialized to that value. Throws an exception if the String cannot be parsed as a byte.
Parameters:
s - the String containing the integer
radix - the radix to be used
Throws:
NumberFormatException - If the String does not contain a parsable byte.

valueOf

public static Byte valueOf(String s)
                    throws NumberFormatException
Assuming the specified String represents a byte, returns a new Byte object initialized to that value. Throws an exception if the String cannot be parsed as a byte. The radix is assumed to be 10.
Parameters:
s - the String containing the integer
Throws:
NumberFormatException - If the String does not contain a parsable byte.

decode

public static Byte decode(String nm)
                   throws NumberFormatException
Decodes a String into a Byte. The String may represent decimal, hexadecimal, and octal numbers.
Parameters:
nm - the string to decode

byteValue

public byte byteValue()
Returns the value of this Byte as a byte.
Overrides:
byteValue in class Number
Tags copied from class: Number
Returns:
the numeric value represented by this object after conversion to type byte.

shortValue

public short shortValue()
Returns the value of this Byte as a short.
Overrides:
shortValue in class Number
Tags copied from class: Number
Returns:
the numeric value represented by this object after conversion to type short.

intValue

public int intValue()
Returns the value of this Byte as an int.
Overrides:
intValue in class Number
Tags copied from class: Number
Returns:
the numeric value represented by this object after conversion to type int.

longValue

public long longValue()
Returns the value of this Byte as a long.
Overrides:
longValue in class Number
Tags copied from class: Number
Returns:
the numeric value represented by this object after conversion to type long.

floatValue

public float floatValue()
Returns the value of this Byte as a float.
Overrides:
floatValue in class Number
Tags copied from class: Number
Returns:
the numeric value represented by this object after conversion to type float.

doubleValue

public double doubleValue()
Returns the value of this Byte as a double.
Overrides:
doubleValue in class Number
Tags copied from class: Number
Returns:
the numeric value represented by this object after conversion to type double.

toString

public String toString()
Returns a String object representing this Byte's value.
Overrides:
toString in class Object
Tags copied from class: Object
Returns:
a string representation of the object.

hashCode

public int hashCode()
Returns a hashcode for this Byte.
Overrides:
hashCode in class Object
Tags copied from class: Object
Returns:
a hash code value for this object.
See Also:
Object.equals(java.lang.Object), Hashtable

equals

public boolean equals(Object obj)
Compares this object to the specified object.
Overrides:
equals in class Object
Parameters:
obj - the object to compare with
Returns:
true if the objects are the same; false otherwise.

compareTo

public int compareTo(Byte anotherByte)
Compares two Bytes numerically.
Parameters:
anotherByte - the Byte to be compared.
Returns:
the value 0 if the argument Byte is equal to this Byte; a value less than 0 if this Byte is numerically less than the Byte argument; and a value greater than 0 if this Byte is numerically greater than the Byte argument (signed comparison).
Since:
JDK1.2

compareTo

public int compareTo(Object o)
Compares this Byte to another Object. If the Object is a Byte, this function behaves like compareTo(Byte). Otherwise, it throws a ClassCastException (as Bytes are comparable only to other Bytes).
Specified by:
compareTo in interface Comparable
Parameters:
o - the Object to be compared.
Returns:
the value 0 if the argument is a Byte numerically equal to this Byte; a value less than 0 if the argument is a Byte numerically greater than this Byte; and a value greater than 0 if the argument is a Byte numerically less than this Byte.
Throws:
ClassCastException - if the argument is not a Byte.
Since:
JDK1.2
See Also:
Comparable

JavaTM 2 Platform
Standard Edition

Submit a bug or feature
Java, Java 2D, and JDBC are a trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-1999 Sun Microsystems, Inc. 901 San Antonio Road,
Palo Alto, California, 94303, U.S.A. All Rights Reserved.