public final class Short extends Number implements Comparable<Short>
short
.Number
,
Serialized FormModifier and Type | Field and Description |
---|---|
static short |
MAX_VALUE
Constant for the maximum
short value, 215-1. |
static short |
MIN_VALUE
Constant for the minimum
short value, -215. |
static int |
SIZE
Constant for the number of bits needed to represent a
short in
two's complement form. |
static Class<Short> |
TYPE
The
Class object that represents the primitive type short . |
Constructor and Description |
---|
Short(short value)
Constructs a new
Short with the specified primitive short value. |
Short(String string)
Constructs a new
Short from the specified string. |
Modifier and Type | Method and Description |
---|---|
byte |
byteValue()
Returns this object's value as a byte.
|
static int |
compare(long lhs,
long rhs)
Compares two
short values. |
int |
compareTo(Short object)
Compares this object to the specified short object to determine their
relative order.
|
static Short |
decode(String string)
Parses the specified string and returns a
Short instance if the
string can be decoded into a short value. |
double |
doubleValue()
Returns this object's value as a double.
|
boolean |
equals(Object object)
Compares this instance with the specified object and indicates if they
are equal.
|
float |
floatValue()
Returns this object's value as a float.
|
int |
hashCode()
Returns an integer hash code for this object.
|
int |
intValue()
Returns this object's value as an int.
|
long |
longValue()
Returns this object's value as a long.
|
static short |
parseShort(String string)
Parses the specified string as a signed decimal short value.
|
static short |
parseShort(String string,
int radix)
Parses the specified string as a signed short value using the specified
radix.
|
static short |
reverseBytes(short s)
Reverses the bytes of the specified short.
|
short |
shortValue()
Gets the primitive value of this short.
|
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
static String |
toString(short value)
Returns a string containing a concise, human-readable description of the
specified short value with radix 10.
|
static Short |
valueOf(short s)
Returns a
Short instance for the specified short value. |
static Short |
valueOf(String string)
Parses the specified string as a signed decimal short value.
|
static Short |
valueOf(String string,
int radix)
Parses the specified string as a signed short value using the specified
radix.
|
public static final short MAX_VALUE
short
value, 215-1.public static final short MIN_VALUE
short
value, -215.public static final int SIZE
short
in
two's complement form.public Short(String string) throws NumberFormatException
Short
from the specified string.string
- the string representation of a short value.NumberFormatException
- if string
cannot be parsed as a short value.parseShort(String)
public Short(short value)
Short
with the specified primitive short value.value
- the primitive short value to store in the new instance.public byte byteValue()
Number
public int compareTo(Short object)
compareTo
in interface Comparable<Short>
object
- the short object to compare this object to.object
; 0 if the value of this short and the
value of object
are equal; a positive value if the value
of this short is greater than the value of object
.NullPointerException
- if object
is null.Comparable
public static int compare(long lhs, long rhs)
short
values.public static Short decode(String string) throws NumberFormatException
Short
instance if the
string can be decoded into a short value. The string may be an optional
minus sign "-" followed by a hexadecimal ("0x..." or "#..."), octal
("0..."), or decimal ("...") representation of a short.string
- a string representation of a short value.Short
containing the value represented by
string
.NumberFormatException
- if string
cannot be parsed as a short value.public double doubleValue()
Number
doubleValue
in class Number
public boolean equals(Object object)
object
must be an instance of
Short
and have the same short value as this object.equals
in class Object
object
- the object to compare this short with.true
if the specified object is equal to this
Short
; false
otherwise.Object.hashCode()
public float floatValue()
Number
floatValue
in class Number
public int hashCode()
Object
Object.equals(java.lang.Object)
returns true
must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode
method
if you intend implementing your own hashCode
method.
hashCode
in class Object
Object.equals(java.lang.Object)
public int intValue()
Number
public long longValue()
Number
public static short parseShort(String string) throws NumberFormatException
string
- the string representation of a short value.string
.NumberFormatException
- if string
cannot be parsed as a short value.public static short parseShort(String string, int radix) throws NumberFormatException
string
- the string representation of a short value.radix
- the radix to use when parsing.string
using
radix
.NumberFormatException
- if string
cannot be parsed as a short value, or
radix < Character.MIN_RADIX ||
radix > Character.MAX_RADIX
.public short shortValue()
shortValue
in class Number
public String toString()
Object
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.
public static String toString(short value)
value
- the short to convert to a string.value
.public static Short valueOf(String string) throws NumberFormatException
string
- the string representation of a short value.Short
instance containing the short value represented
by string
.NumberFormatException
- if string
cannot be parsed as a short value.parseShort(String)
public static Short valueOf(String string, int radix) throws NumberFormatException
string
- the string representation of a short value.radix
- the radix to use when parsing.Short
instance containing the short value represented
by string
using radix
.NumberFormatException
- if string
cannot be parsed as a short value, or
radix < Character.MIN_RADIX ||
radix > Character.MAX_RADIX
.parseShort(String, int)
public static short reverseBytes(short s)
s
- the short value for which to reverse bytes.public static Short valueOf(short s)
Short
instance for the specified short value.
If it is not necessary to get a new Short
instance, it is
recommended to use this method instead of the constructor, since it
maintains a cache of instances which may result in better performance.
s
- the short value to store in the instance.Short
instance containing s
.