Skip to content

Most visited

Recently visited

navigation
Added in API level 1

Short

public final class Short
extends Number implements Comparable<Short>

java.lang.Object
   ↳ java.lang.Number
     ↳ java.lang.Short


The wrapper for the primitive type short.

See also:

Summary

Constants

short MAX_VALUE

Constant for the maximum short value, 215-1.

short MIN_VALUE

Constant for the minimum short value, -215.

int SIZE

Constant for the number of bits needed to represent a short in two's complement form.

Fields

public static final Class<Short> TYPE

The Class object that represents the primitive type short.

Public constructors

Short(String string)

Constructs a new Short from the specified string.

Short(short value)

Constructs a new Short with the specified primitive short value.

Public methods

byte byteValue()

Returns this object's value as a byte.

static int compare(short lhs, short 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, int radix)

Parses the specified string as a signed short value using the specified radix.

static short parseShort(String string)

Parses the specified string as a signed decimal short value.

static short reverseBytes(short s)

Reverses the bytes of the specified short.

short shortValue()

Gets the primitive value of this short.

static String toString(short value)

Returns a string containing a concise, human-readable description of the specified short value with radix 10.

String toString()

Returns a string containing a concise, human-readable description of this object.

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.

static Short valueOf(short s)

Returns a Short instance for the specified short value.

Inherited methods

From class java.lang.Number
From class java.lang.Object
From interface java.lang.Comparable

Constants

MAX_VALUE

Added in API level 1
short MAX_VALUE

Constant for the maximum short value, 215-1.

Constant Value: 32767 (0x00007fff)

MIN_VALUE

Added in API level 1
short MIN_VALUE

Constant for the minimum short value, -215.

Constant Value: -32768 (0xffff8000)

SIZE

Added in API level 1
int SIZE

Constant for the number of bits needed to represent a short in two's complement form.

Constant Value: 16 (0x00000010)

Fields

TYPE

Added in API level 1
Class<Short> TYPE

The Class object that represents the primitive type short.

Public constructors

Short

Added in API level 1
Short (String string)

Constructs a new Short from the specified string.

Parameters
string String: the string representation of a short value.
Throws
NumberFormatException if string cannot be parsed as a short value.

See also:

Short

Added in API level 1
Short (short value)

Constructs a new Short with the specified primitive short value.

Parameters
value short: the primitive short value to store in the new instance.

Public methods

byteValue

Added in API level 1
byte byteValue ()

Returns this object's value as a byte. Might involve rounding and/or truncating the value, so it fits into a byte.

Returns
byte the primitive byte value of this object.

compare

Added in API level 19
int compare (short lhs, 
                short rhs)

Compares two short values.

Parameters
lhs short
rhs short
Returns
int 0 if lhs = rhs, less than 0 if lhs < rhs, and greater than 0 if lhs > rhs.

compareTo

Added in API level 1
int compareTo (Short object)

Compares this object to the specified short object to determine their relative order.

Parameters
object Short: the short object to compare this object to.
Returns
int a negative value if the value of this short is less than the value of 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.
Throws
NullPointerException if object is null.

See also:

decode

Added in API level 1
Short decode (String string)

Parses the specified string and returns a 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.

Parameters
string String: a string representation of a short value.
Returns
Short a Short containing the value represented by string.
Throws
NumberFormatException if string cannot be parsed as a short value.

doubleValue

Added in API level 1
double doubleValue ()

Returns this object's value as a double. Might involve rounding.

Returns
double the primitive double value of this object.

equals

Added in API level 1
boolean equals (Object object)

Compares this instance with the specified object and indicates if they are equal. In order to be equal, object must be an instance of Short and have the same short value as this object.

Parameters
object Object: the object to compare this short with.
Returns
boolean true if the specified object is equal to this Short; false otherwise.

floatValue

Added in API level 1
float floatValue ()

Returns this object's value as a float. Might involve rounding.

Returns
float the primitive float value of this object.

hashCode

Added in API level 1
int hashCode ()

Returns an integer hash code for this object. By contract, any two objects for which equals(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.

Returns
int this object's hash code.

intValue

Added in API level 1
int intValue ()

Returns this object's value as an int. Might involve rounding and/or truncating the value, so it fits into an int.

Returns
int the primitive int value of this object.

longValue

Added in API level 1
long longValue ()

Returns this object's value as a long. Might involve rounding and/or truncating the value, so it fits into a long.

Returns
long the primitive long value of this object.

parseShort

Added in API level 1
short parseShort (String string, 
                int radix)

Parses the specified string as a signed short value using the specified radix. The ASCII character - ('-') is recognized as the minus sign.

Parameters
string String: the string representation of a short value.
radix int: the radix to use when parsing.
Returns
short the primitive short value represented by string using radix.
Throws
NumberFormatException if string cannot be parsed as a short value, or radix < Character.MIN_RADIX || radix > Character.MAX_RADIX.

parseShort

Added in API level 1
short parseShort (String string)

Parses the specified string as a signed decimal short value. The ASCII character - ('-') is recognized as the minus sign.

Parameters
string String: the string representation of a short value.
Returns
short the primitive short value represented by string.
Throws
NumberFormatException if string cannot be parsed as a short value.

reverseBytes

Added in API level 1
short reverseBytes (short s)

Reverses the bytes of the specified short.

Parameters
s short: the short value for which to reverse bytes.
Returns
short the reversed value.

shortValue

Added in API level 1
short shortValue ()

Gets the primitive value of this short.

Returns
short this object's primitive value.

toString

Added in API level 1
String toString (short value)

Returns a string containing a concise, human-readable description of the specified short value with radix 10.

Parameters
value short: the short to convert to a string.
Returns
String a printable representation of value.

toString

Added in API level 1
String toString ()

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
String a printable representation of this object.

valueOf

Added in API level 1
Short valueOf (String string)

Parses the specified string as a signed decimal short value.

Parameters
string String: the string representation of a short value.
Returns
Short a Short instance containing the short value represented by string.
Throws
NumberFormatException if string cannot be parsed as a short value.

See also:

valueOf

Added in API level 1
Short valueOf (String string, 
                int radix)

Parses the specified string as a signed short value using the specified radix.

Parameters
string String: the string representation of a short value.
radix int: the radix to use when parsing.
Returns
Short a Short instance containing the short value represented by string using radix.
Throws
NumberFormatException if string cannot be parsed as a short value, or radix < Character.MIN_RADIX || radix > Character.MAX_RADIX.

See also:

valueOf

Added in API level 1
Short valueOf (short s)

Returns a 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.

Parameters
s short: the short value to store in the instance.
Returns
Short a Short instance containing s.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.