public final class Short
extends Number implements Comparable<Short>
| java.lang.Object | ||
| java.lang.Number | ||
| java.lang.Short | ||
Short类将原始类型short的值包装在对象中。 类型为Short的对象包含类型为short的单个字段。
此外,该类提供了几种将 short转换为 String和 String转换为 short ,以及处理 short时有用的其他常量和方法。
也可以看看:
常量(Constants) |
|
|---|---|
int |
BYTES 以二进制补码形式表示 |
short |
MAX_VALUE 一个常数保持最大值a |
short |
MIN_VALUE 一个常量可以保持最小值a |
int |
SIZE 以二进制补码形式表示 |
Fields |
|
|---|---|
public static final Class<Short> |
TYPE 表示原始类型 |
Public constructors |
|
|---|---|
Short(short value) 构造一个新分配的 |
|
Short(String s) 构造一个新分配 |
|
公共方法(Public methods) |
|
|---|---|
byte |
byteValue() 返回此值 |
static int |
compare(short x, short y) 以数字方式比较两个 |
int |
compareTo(Short anotherShort) 以数字方式比较两个 |
static Short |
decode(String nm) 将 |
double |
doubleValue() 返回此值 |
boolean |
equals(Object obj) 将此对象与指定的对象进行比较。 |
float |
floatValue() 返回此值 |
static int |
hashCode(short value) 返回 |
int |
hashCode() 返回此 |
int |
intValue() 返回此值 |
long |
longValue() 返回此值 |
static short |
parseShort(String s) 将字符串参数解析为带符号的十进制数 |
static short |
parseShort(String s, int radix) 将字符串参数解析为由第二个参数指定的基数中的带符号的 |
static short |
reverseBytes(short i) 返回通过颠倒指定的 |
short |
shortValue() 返回此值 |
static String |
toString(short s) 返回一个新 |
String |
toString() 返回代表此 |
static Short |
valueOf(String s) 返回保存由指定的 |
static Short |
valueOf(short s) 返回表示指定的 |
static Short |
valueOf(String s, int radix) 返回一个 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Number
|
|
java.lang.Object
|
|
java.lang.Comparable
|
|
Short (short value)
构造一个新分配的 Short对象,该对象表示指定的 short值。
| 参数(Parameters) | |
|---|---|
value |
short: the value to be represented by the Short. |
Short (String s)
构造一个新分配的Short对象,该对象表示由String参数指示的short值。 该字符串short与parseShort方法所用的方式完全相同的方式转换为short值。
| 参数(Parameters) | |
|---|---|
s |
String: the String to be converted to a Short |
| 抛出异常(Throws) | |
|---|---|
NumberFormatException |
If the String does not contain a parsable short. |
byte byteValue ()
返回此值 Short为 byte 。
| 返回(Returns) | |
|---|---|
byte |
the numeric value represented by this object after conversion to type byte. |
int compare (short x,
short y)
用数字比较两个short值。 返回的值与以下内容返回的值相同:
Short.valueOf(x).compareTo(Short.valueOf(y))
| 参数(Parameters) | |
|---|---|
x |
short: the first short to compare |
y |
short: the second short to compare |
| 返回(Returns) | |
|---|---|
int |
the value 0 if x == y; a value less than 0 if x < y; and a value greater than 0 if x > y |
int compareTo (Short anotherShort)
以数字方式比较两个 Short对象。
| 参数(Parameters) | |
|---|---|
anotherShort |
Short: the Short to be compared. |
| 返回(Returns) | |
|---|---|
int |
the value 0 if this Short is equal to the argument Short; a value less than 0 if this Short is numerically less than the argument Short; and a value greater than 0 if this Short is numerically greater than the argument Short (signed comparison). |
Short decode (String nm)
将String解码为Short 。 接受由以下语法给出的十进制,十六进制和八进制数字:
DecimalNumeral, HexDigits, and OctalDigits are as defined in section 3.10.1 of The JavaTM Language Specification, except that underscores are not accepted between digits.
- DecodableString:
- Signopt DecimalNumeral
- Signopt
0xHexDigits- Signopt
0XHexDigits- Signopt
#HexDigits- Signopt
0OctalDigits- Sign:
-+
可选符号和/或基数说明符(“ 0x ”,“ 0X ”,“ # ”或前导零)后面的字符序列按Short.parseShort方法用指示的基数(10,16或8)进行解析。 这个字符序列必须表示一个正值, NumberFormatException将抛出一个NumberFormatException 。 如果指定的String第一个字符是负号,则结果将被否定。 String中不允许有空白字符。
| 参数(Parameters) | |
|---|---|
nm |
String: the String to decode. |
| 返回(Returns) | |
|---|---|
Short |
a Short object holding the short value represented by nm |
| 抛出异常(Throws) | |
|---|---|
NumberFormatException |
if the String does not contain a parsable short. |
double doubleValue ()
返回此值 Short为 double 。
| 返回(Returns) | |
|---|---|
double |
the numeric value represented by this object after conversion to type double. |
boolean equals (Object obj)
将此对象与指定的对象进行比较。 结果为true当且仅当参数不是null并且是一个Short对象包含与此对象相同的值short值。
| 参数(Parameters) | |
|---|---|
obj |
Object: the object to compare with |
| 返回(Returns) | |
|---|---|
boolean |
true if the objects are the same; false otherwise. |
float floatValue ()
返回此值 Short为 float 。
| 返回(Returns) | |
|---|---|
float |
the numeric value represented by this object after conversion to type float. |
int hashCode (short value)
返回short值的散列码; 与Short.hashCode()兼容。
| 参数(Parameters) | |
|---|---|
value |
short: the value to hash |
| 返回(Returns) | |
|---|---|
int |
a hash code value for a short value. |
int hashCode ()
返回此Short的哈希码; 等于调用intValue()的结果。
| 返回(Returns) | |
|---|---|
int |
a hash code value for this Short |
int intValue ()
返回此值 Short为 int 。
| 返回(Returns) | |
|---|---|
int |
the numeric value represented by this object after conversion to type int. |
long longValue ()
返回此值 Short为 long 。
| 返回(Returns) | |
|---|---|
long |
the numeric value represented by this object after conversion to type long. |
short parseShort (String s)
将字符串参数解析为带符号的十进制数short 。 字符串中的字符必须全部为十进制数字,但第一个字符可能是ASCII减号'-' ( '\u002D' )以指示负值或指示正值的ASCII加号'+' ( '\u002B' )。 返回结果short值,就好像将参数和基数10作为parseShort(java.lang.String, int)方法的参数一样给出。
| 参数(Parameters) | |
|---|---|
s |
String: a String containing the short representation to be parsed |
| 返回(Returns) | |
|---|---|
short |
the short value represented by the argument in decimal. |
| 抛出异常(Throws) | |
|---|---|
NumberFormatException |
If the string does not contain a parsable short. |
short parseShort (String s, int radix)
将字符串参数解析为由第二个参数指定的基数中的带符号的short 。 除了第一个字符可能是ASCII减号'-' ( '\u002D' )以指示负值或ASCII加号之外,字符串中的字符必须全部是指定基数的数字(由digit(char, int)返回非负值'\u002D' ) '+' ( '\u002B' )表示正值。 返回结果short值。
如果发生以下任何情况,将引发 NumberFormatException类型的异常:
null or is a string of length zero. MIN_RADIX or larger than MAX_RADIX. '-' ('\u002D') or plus sign '+' ('\u002B') provided that the string is longer than length 1. short. | 参数(Parameters) | |
|---|---|
s |
String: the String containing the short representation to be parsed |
radix |
int: the radix to be used while parsing s |
| 返回(Returns) | |
|---|---|
short |
the short represented by the string argument in the specified radix. |
| 抛出异常(Throws) | |
|---|---|
NumberFormatException |
If the String does not contain a parsable short. |
short reverseBytes (short i)
返回通过颠倒指定的 short值的二进制补码表示中的字节顺序而获得的值。
| 参数(Parameters) | |
|---|---|
i |
short
|
| 返回(Returns) | |
|---|---|
short |
the value obtained by reversing (or, equivalently, swapping) the bytes in the specified short value. |
short shortValue ()
返回此值 Short为 short 。
| 返回(Returns) | |
|---|---|
short |
the numeric value represented by this object after conversion to type short. |
String toString (short s)
返回一个新String表示指定对象short 。 基数假定为10。
| 参数(Parameters) | |
|---|---|
s |
short: the short to be converted |
| 返回(Returns) | |
|---|---|
String |
the string representation of the specified short |
也可以看看:
String toString ()
返回表示此Short的值的String对象。 该值被转换为带符号的十进制表示并作为字符串返回,就好像short值作为toString(short)方法的参数toString(short) 。
| 返回(Returns) | |
|---|---|
String |
a string representation of the value of this object in base 10. |
Short valueOf (String s)
返回保存由指定的String给出的值的Short对象。 参数被解释为表示一个有符号的十进制数short ,就好像参数被赋予parseShort(java.lang.String)方法一样。 结果是Short对象,该对象表示由该字符串指定的short值。
换句话说,该方法返回一个 Short对象,其值等于:
new Short(Short.parseShort(s))
| 参数(Parameters) | |
|---|---|
s |
String: the string to be parsed |
| 返回(Returns) | |
|---|---|
Short |
a Short object holding the value represented by the string argument |
| 抛出异常(Throws) | |
|---|---|
NumberFormatException |
If the String does not contain a parsable short. |
Short valueOf (short s)
返回表示指定的short值的Short实例。 如果不需要新的Short实例,通常应该优先使用此方法,而不是构造函数Short(short) ,因为此方法通过缓存经常请求的值可能会产生显着更好的空间和时间性能。 此方法将始终缓存-128至127(含)范围内的值,并可缓存此范围之外的其他值。
| 参数(Parameters) | |
|---|---|
s |
short: a short value. |
| 返回(Returns) | |
|---|---|
Short |
a Short instance representing s. |
Short valueOf (String s, int radix)
返回一个Short对象,该对象在使用第二个参数给出的基数进行分析时保存从指定的String提取的值。 第一个参数被解释为表示由第二个参数指定的基数中的带符号的short ,就像参数被赋予parseShort(java.lang.String, int)方法一样。 结果是一个Short对象,它表示由字符串指定的short值。
换句话说,这个方法返回一个 Short对象,其值等于:
new Short(Short.parseShort(s, radix))
| 参数(Parameters) | |
|---|---|
s |
String: the string to be parsed |
radix |
int: the radix to be used in interpreting s |
| 返回(Returns) | |
|---|---|
Short |
a Short object holding the value represented by the string argument in the specified radix. |
| 抛出异常(Throws) | |
|---|---|
NumberFormatException |
If the String does not contain a parsable short. |