GeezerVison is showing docs.oracle.com — Short (Java Platform SE 8 )
Java™ Platform Standard Ed. 8
compact1, compact2, compact3
java.lang
Class Short
-
-
Field Summary
Fields
| Modifier and Type |
Field |
Description |
static int |
BYTES |
The number of bytes used to represent a short value in two's
complement binary form.
|
static short |
MAX_VALUE |
A constant holding the maximum value a short can
have, 215-1.
|
static short |
MIN_VALUE |
A constant holding the minimum value a short can
have, -215.
|
static int |
SIZE |
The number of bits used to represent a short value in two's
complement binary form.
|
static Class<Short> |
TYPE |
The Class instance representing the primitive type
short.
|
-
Constructor Summary
Constructors
| Constructor |
Description |
Short(short value) |
Constructs a newly allocated Short object that
represents the specified short value.
|
Short(String s) |
Constructs a newly allocated Short object that
represents the short value indicated by the
String parameter.
|
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods
| Modifier and Type |
Method |
Description |
byte |
byteValue() |
Returns the value of this Short as a byte after
a narrowing primitive conversion.
|
static int |
compare(short x,
short y) |
Compares two short values numerically.
|
int |
compareTo(Short anotherShort) |
Compares two Short objects numerically.
|
static Short |
decode(String nm) |
Decodes a String into a Short.
|
double |
doubleValue() |
Returns the value of this Short as a double
after a widening primitive conversion.
|
boolean |
equals(Object obj) |
Compares this object to the specified object.
|
float |
floatValue() |
Returns the value of this Short as a float
after a widening primitive conversion.
|
int |
hashCode() |
Returns a hash code for this Short; equal to the result
of invoking intValue().
|
static int |
hashCode(short value) |
Returns a hash code for a short value; compatible with
Short.hashCode().
|
int |
intValue() |
Returns the value of this Short as an int after
a widening primitive conversion.
|
long |
longValue() |
Returns the value of this Short as a long after
a widening primitive conversion.
|
static short |
parseShort(String s) |
Parses the string argument as a signed decimal short.
|
static short |
parseShort(String s,
int radix) |
Parses the string argument as a signed short in the
radix specified by the second argument.
|
static short |
reverseBytes(short i) |
Returns the value obtained by reversing the order of the bytes in the
two's complement representation of the specified short value.
|
short |
shortValue() |
Returns the value of this Short as a
short.
|
String |
toString() |
Returns a String object representing this
Short's value.
|
static String |
toString(short s) |
Returns a new String object representing the
specified short.
|
static int |
toUnsignedInt(short x) |
Converts the argument to an int by an unsigned
conversion.
|
static long |
toUnsignedLong(short x) |
Converts the argument to a long by an unsigned
conversion.
|
static Short |
valueOf(short s) |
Returns a Short instance representing the specified
short value.
|
static Short |
valueOf(String s) |
Returns a Short object holding the
value given by the specified String.
|
static Short |
valueOf(String s,
int radix) |
Returns a Short object holding the value
extracted from the specified String when parsed
with the radix given by the second argument.
|
-
-
Constructor Detail
-
Short
public Short(String s)
throws NumberFormatException
Constructs a newly allocated Short object that
represents the short value indicated by the
String parameter. The string is converted to a
short value in exactly the manner used by the
parseShort method for radix 10.
- Parameters:
s - the String to be converted to a
Short
- Throws:
NumberFormatException - If the String
does not contain a parsable short.
- See Also:
parseShort(java.lang.String, int)
-
Method Detail
-
toString
public String toString()
Returns a String object representing this
Short's value. The value is converted to signed
decimal representation and returned as a string, exactly as if
the short value were given as an argument to the
toString(short) method.
- Overrides:
toString in class Object
- Returns:
- a string representation of the value of this object in
base 10.
-
equals
public boolean equals(Object obj)
Compares this object to the specified object. The result is
true if and only if the argument is not
null and is a Short object that
contains the same short value as this object.
- Overrides:
equals in class Object
- Parameters:
obj - the object to compare with
- Returns:
true if the objects are the same;
false otherwise.
- See Also:
Object.hashCode(),
HashMap
-
toUnsignedInt
public static int toUnsignedInt(short x)
Converts the argument to an int by an unsigned
conversion. In an unsigned conversion to an int, the
high-order 16 bits of the int are zero and the
low-order 16 bits are equal to the bits of the short argument.
Consequently, zero and positive short values are mapped
to a numerically equal int value and negative short values are mapped to an int value equal to the
input plus 216.
- Parameters:
x - the value to convert to an unsigned int
- Returns:
- the argument converted to
int by an unsigned
conversion
- Since:
- 1.8
-
toUnsignedLong
public static long toUnsignedLong(short x)
Converts the argument to a long by an unsigned
conversion. In an unsigned conversion to a long, the
high-order 48 bits of the long are zero and the
low-order 16 bits are equal to the bits of the short argument.
Consequently, zero and positive short values are mapped
to a numerically equal long value and negative short values are mapped to a long value equal to the
input plus 216.
- Parameters:
x - the value to convert to an unsigned long
- Returns:
- the argument converted to
long by an unsigned
conversion
- Since:
- 1.8
Java™ Platform Standard Ed. 8
Submit a bug or feature For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples. Copyright © 1993, 2026, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
|