public final class Short extends Number implements Comparable<Short>
Short类在一个对象中包含一个基本类型short的值。
类型为Short的对象包含一个类型为short的单个字段。
此外,该类还提供了几种将short转换为String和String转换为short ,以及在处理short时有用的其他常数和方法。
Number , Serialized Form
| Modifier and Type | Field and Description |
|---|---|
static int |
BYTES
用于表示二进制补码二进制形式的
short值的字节数。
|
static short |
MAX_VALUE
持有最大值a
short可以具有2
15 -1。
|
static short |
MIN_VALUE
的常量保持的最小值的
short可以具有,-2
15。
|
static int |
SIZE
用于表示二进制补码二进制形式的
short值的位数。
|
static 类<Short> |
TYPE
类原始类型
short的
类实例。
|
| Constructor and Description |
|---|
Short(short value)
构造一个新分配的
Short对象,表示指定的
short值。
|
Short(String s)
构造一个新分配
Short对象,表示
short由指示值
String参数。
|
| Modifier and Type | Method and Description |
|---|---|
byte |
byteValue()
返回此值
Short为
byte的基本收缩转换后。
|
static int |
compare(short x, short y)
数值比较两个
short数值。
|
int |
compareTo(Short anotherShort)
以数字比较两个
Short对象。
|
static Short |
decode(String nm)
将
String解码为
Short 。
|
double |
doubleValue()
返回此值
Short为
double一个宽元转换后。
|
boolean |
equals(Object obj)
将此对象与指定的对象进行比较。
|
float |
floatValue()
在扩展原始转换后,以
float形式返回此
Short的值。
|
int |
hashCode()
返回这个 Short的哈希码;
等于调用intValue()的结果。
|
static int |
hashCode(short value)
返回一个 short值的哈希码;
兼容Short.hashCode() 。
|
int |
intValue()
返回此的值
Short作为
int加宽原始转换之后。
|
long |
longValue()
返回此值
Short为
long一个宽元转换后。
|
static short |
parseShort(String s)
将字符串参数解析为带符号的十进制
short 。
|
static short |
parseShort(String s, int radix)
将字符串参数解析为由第二个参数指定的基数中的带符号的
short 。
|
static short |
reverseBytes(short i)
返回反转指定的二进制补码表示的字节顺序而获得的值
short值。
|
short |
shortValue()
将此
Short的值作为
short 。
|
String |
toString()
返回一个
String该
Short值的
String对象。
|
static String |
toString(short s)
返回一个新的
String对象,表示指定的
short 。
|
static int |
toUnsignedInt(short x)
的参数的转换
int由无符号转换。
|
static long |
toUnsignedLong(short x)
参数给转换
long由无符号转换。
|
static Short |
valueOf(short s)
返回表示
Short的
short值的
Short实例。
|
static Short |
valueOf(String s)
返回一个
Short物体保持由指定的给定的值
String 。
|
static Short |
valueOf(String s, int radix)
返回一个
Short对象,保存从指定的String
String的值,并用第二个参数给出的基数进行解析。
|
public static final short MIN_VALUE
short可以具有,-2
15。
public static final short MAX_VALUE
short可以具有2
15 -1。
public static final int SIZE
short值的位数。
public static final int BYTES
short值的字节数。
public Short(short value)
Short对象,代表指定的
short值。
value -值由表示
Short 。
public Short(String s) throws NumberFormatException
Short对象,表示short由指示值String参数。
该字符串将转换为short值,恰好与基数为parseShort方法一致。
s -的
String被转换为
Short
NumberFormatException - 如果
String不包含可解析的
short 。
parseShort(java.lang.String, int)
public static String toString(short s)
String对象,表示指定的short 。
基数假定为10。
s -的
short要转换
short
Integer.toString(int)
public static short parseShort(String s, int radix) throws NumberFormatException
short 。
字符串中的字符必须是数字,指定基数(如通过是否确定Character.digit(char, int)返回一个非负的值)不同之处在于第一个字符可以是ASCII减号'-' ( '\u002D' ),以指示一个负值或ASCII加号'+' ( '\u002B' )以表示正值。
返回结果为short值。
如果发生以下任何一种情况,则抛出类型为NumberFormatException的异常:
null或是长度为零的字符串。 Character.MIN_RADIX或大于Character.MAX_RADIX 。 '-' ( '\u002D' )或加号'+' ( '\u002B' ),前提是字符串长于长度1。 short的值。 s - 包含要解析的
String表示的
short
radix - 解析时使用的基数
s
short通过指定基数字符串参数表示。
NumberFormatException - 如果
String不包含可解析的
short 。
public static short parseShort(String s) throws NumberFormatException
short 。
字符串中的字符都必须是十进制数字,除了第一个字符可能是ASCII减号'-' ( '\u002D' )以指示负值或ASCII加号'+' ( '\u002B' )以指示正值。
返回的结果为short ,正如参数和小数10被赋予parseShort(java.lang.String, int)方法的参数一样。
s - a
String ,
short包含要解析的
short表示
short值由参数以十进制表示。
NumberFormatException - 如果字符串不包含可解析的
short 。
public static Short valueOf(String s, int radix) throws NumberFormatException
String的值的Short对象。
第一个参数被解释为表示由第二个参数指定的基数中的带符号的short ,就好像该参数被赋予parseShort(java.lang.String, int)方法一样。
结果是一个Short对象,表示由字符串指定的short值。
换句话说,这个方法返回一个Short对象的值等于:
new Short(Short.parseShort(s, radix))
s - 要解析的字符串
radix - 用于解释的基数
s
Short对象,保存由指定基数中的字符串参数表示的值。
NumberFormatException - 如果
String不包含可解析的
short 。
public static Short valueOf(String s) throws NumberFormatException
Short物体保持由指定的给定的值String 。
该参数被解释为表示一个有符号的十进制short ,完全相同于parseShort(java.lang.String)方法的参数。
结果是一个Short对象,表示由字符串指定的short值。
换句话说,该方法返回一个等于下列值的Short对象:
new Short(Short.parseShort(s))
s - 要解析的字符串
Short对象
NumberFormatException - 如果
String不包含可解析的
short 。
public static Short valueOf(short s)
Short short值的Short实例。
如果不需要新的Short实例,则该方法通常优先于构造函数Short(short)使用 ,因为该方法可能通过缓存经常请求的值而产生明显更好的空间和时间性能。
此方法将始终缓存-128到127(含)范围内的值,并可能会超出此范围之外的其他值。
s - 一个很短的价值。
Short实例代表
s 。
public static Short decode(String nm) throws NumberFormatException
String解码为Short 。
接受以下语法给出的十进制,十六进制和八进制数:
DecimalNumeral,HexDigits,和OctalDigits如在The Java™ Language Specification 3.10.1部分所定义,所不同的是下划线不数字之间接受。
- DecodableString:
- Signopt DecimalNumeral
- Signopt
0xHexDigits- Signopt
0XHexDigits- Signopt
#HexDigits- Signopt
0OctalDigits- Sign:
-+
可选符号和/或基数说明符(“ 0x ”,“ 0X ”,“ # ”或前导零)之后的Short.parseShort由具有指示的基数(10,16或8)的Short.parseShort方法进行解析。 这个字符序列必须表示一个正值,或者NumberFormatException将被抛出。 如果指定的第一个字符的结果是否定String是减号。 String中不允许使用String 。
nm - 要解码的
String 。
Short对象持有
short代表的
nm
NumberFormatException - 如果
String不包含可解析的
short 。
parseShort(java.lang.String, int)
public byte byteValue()
Short为
byte的基本收缩转换后。
public short shortValue()
Short为
short 。
shortValue在
Number
short类型后由该对象表示的数值。
public int intValue()
Short作为
int加宽原始转换之后。
public long longValue()
Short为
long一个宽元转换后。
public float floatValue()
Short为
float一个宽元转换后。
floatValue在
Number
float之后表示的
float 。
public double doubleValue()
Short为
double一个宽元转换后。
doubleValue在
Number
double类型后表示的
double 。
public String toString()
Short的值的String对象。
该值被转换为带符号的十进制表示,并作为字符串返回,就像short值作为toString(short)方法的参数一样 。
public int hashCode()
Short的哈希码;
等于调用intValue()的结果。
hashCode在
Object
Short的哈希码值
Object.equals(java.lang.Object) ,
System.identityHashCode(java.lang.Object)
public static int hashCode(short value)
short值的哈希码;
兼容Short.hashCode() 。
value - 值的哈希
short值的哈希码值。
public boolean equals(Object obj)
true当且仅当参数不是null并且是一个Short对象包含与此对象相同的short值。
equals在
Object
obj - 要比较的对象
true如果对象相同;
false否则。
Object.hashCode() , HashMap
public int compareTo(Short anotherShort)
Short对象。
compareTo在接口
Comparable<Short>
anotherShort - 要比较的
Short 。
0如果这Short等于参数Short ;
的值小于0如果这Short在数值上小于该参数Short ;
和大于一个值0如果此Short在数值上大于该参数Short (带符号的比较)。
public static int compare(short x,
short y)
short数值。
返回的值与以下内容相同:
Short.valueOf(x).compareTo(Short.valueOf(y))
x - 第一个
short进行比较
y - 第二个
short进行比较
0如果x == y ;
一个值小于0如果x < y ;
和值大于0如果x > y
public static short reverseBytes(short i)
short值。
i - 要颠倒其字节的值
short值。
public static int toUnsignedInt(short x)
int由无符号转换。
在无符号转换到int ,所述的高阶16位int是零和低阶16个比特都等于的位short的说法。
因此,零和正值short值映射到数字相等的int值,负值short值映射到等于输入加上2 16的int值。
x - 要转换为无符号
int的值
int由无符号转换
public static long toUnsignedLong(short x)
long由无符号转换。
在一个无符号转换为long ,所述的高阶48位long是零和低阶16个比特都等于的位short的说法。
因此,零和正值short值被映射到数字相等的long值,负值short映射到等于输入加上2 16的long值。
x - 要转换为无符号
long的值
long由无符号转换
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, 2014, Oracle and/or its affiliates. All rights reserved.