- java.lang.Object
-
- java.lang.Number
-
- java.lang.Short
-
- 实现的所有接口
-
Serializable,Comparable<Short>
public final class Short extends Number implements Comparable<Short>
Short类在对象中包装基本类型short的值。 类型为Short的对象包含单个字段,其类型为short。此外,此类提供了几种将
short转换为String和String转换为short,以及处理short时有用的其他常量和方法。- 从以下版本开始:
- 1.1
- 另请参见:
-
Number, Serialized Form
-
-
方法摘要
所有方法 静态方法 实例方法 具体的方法 变量和类型 方法 描述 bytebyteValue()返回此值Short为byte的基本收缩转换后。static intcompare(short x, short y)以数字方式比较两个short值。intcompareTo(Short anotherShort)用数字比较两个Short对象。static intcompareUnsigned(short x, short y)比较两个short值,以数值方式将值视为无符号。static Shortdecode(String nm)将String解码为Short。doubledoubleValue()返回此值Short为double一个宽元转换后。booleanequals(Object obj)将此对象与指定的对象进行比较。floatfloatValue()返回此值Short为float一个宽元转换后。inthashCode()返回此Short的哈希码; 等于调用intValue()的结果。static inthashCode(short value)返回short值的哈希码; 与Short.hashCode()兼容。intintValue()返回此的值Short作为int加宽原始转换之后。longlongValue()返回此值Short为long一个宽元转换后。static shortparseShort(String s)将字符串参数解析为带符号的小数short。static shortparseShort(String s, int radix)将字符串参数解析为第二个参数指定的基数中的带符号short。static shortreverseBytes(short i)返回通过反转指定的short值的二进制补码表示中的字节顺序获得的值。shortshortValue()返回此值Short为short。StringtoString()返回表示此Short值的String对象。static StringtoString(short s)返回表示指定的short的新String对象。static inttoUnsignedInt(short x)通过无符号转换将参数转换为int。static longtoUnsignedLong(short x)通过无符号转换将参数转换为long。static ShortvalueOf(short s)返回表示指定的short值的Short实例。static ShortvalueOf(String s)返回一个Short对象,其中包含指定的String给定的值。static ShortvalueOf(String s, int radix)返回一个Short对象,当使用第二个参数给出的基数进行解析时,该对象保存从指定的String提取的值。
-
-
-
字段详细信息
-
MIN_VALUE
public static final short MIN_VALUE
持有最小值的常数short可以具有,-2 15 。- 另请参见:
- 常数字段值
-
MAX_VALUE
public static final short MAX_VALUE
保持最大值的常数short可以具有,2 15 -1。- 另请参见:
- 常数字段值
-
SIZE
public static final int SIZE
用于表示二进制补码二进制形式的short值的位数。- 从以下版本开始:
- 1.5
- 另请参见:
- 常数字段值
-
BYTES
public static final int BYTES
用于表示二进制补码二进制形式的short值的字节数。- 从以下版本开始:
- 1.8
- 另请参见:
- 常数字段值
-
-
构造方法详细信息
-
Short
@Deprecated(since="9") public Short(short value)
Deprecated.It is rarely appropriate to use this constructor. The static factoryvalueOf(short)is generally a better choice, as it is likely to yield significantly better space and time performance.构造一个新分配的Short对象,该对象表示指定的short值。- 参数
-
value- 由Short表示的值。
-
Short
@Deprecated(since="9") public Short(String s) throws NumberFormatException
Deprecated.It is rarely appropriate to use this constructor. UseparseShort(String)to convert a string to ashortprimitive, or usevalueOf(String)to convert a string to aShortobject.构造一个新分配Short对象,表示short由指示值String参数。 该字符串parseShort方法用于基数10的方式转换为short值。- 参数
-
s-的String,以被转换为Short - 异常
-
NumberFormatException- 如果String不包含可分析的short。
-
-
方法详细信息
-
toString
public static String toString(short s)
返回表示指定的short的新String对象。 假设基数为10。- 参数
-
s- 要转换的short - 结果
-
指定的
short的字符串表示short - 另请参见:
-
Integer.toString(int)
-
parseShort
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。
- 第一个参数是
-
parseShort
public static short parseShort(String s) throws NumberFormatException
将字符串参数解析为带符号的小数short。 字符串中的字符必须全部为十进制数字,除了第一个字符可以是ASCII减号'-'('\u002D')以指示负值或ASCII加号'+'('\u002B')以指示正值。 返回得到的short值,就像参数和基数10作为parseShort(java.lang.String, int)方法的参数一样 。- 参数
-
s-一个String含有short表示被解析 - 结果
-
由十进制参数表示的
short值。 - 异常
-
NumberFormatException- 如果字符串不包含可分析的short。
-
valueOf
public static Short valueOf(String s, int radix) throws NumberFormatException
返回Short对象,当使用第二个参数给出的基数进行解析时,该对象保存从指定的String提取的值。 第一个参数被解释为表示由第二个参数指定的基数中的带符号short,就像将参数赋予parseShort(java.lang.String, int)方法一样。 结果是Short对象,表示由字符串指定的short值。换句话说,此方法返回
Short对象,其值等于:new Short(Short.parseShort(s, radix))- 参数
-
s- 要解析的字符串 -
radix- 用于解释s的基数 - 结果
-
Short对象,保存指定基数中字符串参数表示的值。 - 异常
-
NumberFormatException- 如果String不包含可分析的short。
-
valueOf
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。
-
valueOf
public static Short valueOf(short s)
返回表示指定的short值的Short实例。 如果不需要新的Short实例,则通常应优先使用此方法,而不是构造函数Short(short),因为此方法可能通过缓存频繁请求的值来显着提高空间和时间性能。 此方法将始终缓存-128到127(包括端点)范围内的值,并可以缓存此范围之外的其他值。- 参数
-
s- 较短的值。 - 结果
-
Short实例,代表s。 - 从以下版本开始:
- 1.5
-
decode
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)进行解析。 此字符序列必须表示正值或将抛出NumberFormatException。 如果指定的String第一个字符是减号,则结果为否定。String中不允许使用空格字符。- 参数
-
nm- 要解码的String。 - 结果
-
持有
short值的Short对象,由nm表示 - 异常
-
NumberFormatException- 如果String不包含可分析的short。 - 另请参见:
-
parseShort(java.lang.String, int)
-
byteValue
public byte byteValue()
返回此值Short为byte的基本收缩转换后。
-
shortValue
public short shortValue()
返回此值Short为short。- 重写:
-
shortValue在类Number - 结果
-
转换为类型
short后此对象表示的数值。
-
intValue
public int intValue()
返回此的值Short作为int加宽原始转换之后。
-
longValue
public long longValue()
返回此值Short为long一个宽元转换后。
-
floatValue
public float floatValue()
返回此值Short为float一个宽元转换后。- Specified by:
-
floatValue在类Number - 结果
-
转换为类型
float后此对象表示的数值。 - See The Java™ Language Specification:
- 5.1.2拓宽原始转换
-
doubleValue
public double doubleValue()
返回此值Short为double一个宽元转换后。- Specified by:
-
doubleValue在类Number - 结果
-
转换为类型
double后此对象表示的数值。 - See The Java™ Language Specification:
- 5.1.2拓宽原始转换
-
toString
public String toString()
返回表示此Short值的String对象。 该值将转换为带符号的十进制表示形式并作为字符串返回,就像short值作为toString(short)方法的参数一样 。
-
hashCode
public int hashCode()
返回此Short的哈希码; 等于调用intValue()的结果。- 重写:
-
hashCode在类Object - 结果
-
此
Short的哈希码值 - 另请参见:
-
Object.equals(java.lang.Object),System.identityHashCode(java.lang.Object)
-
hashCode
public static int hashCode(short value)
返回short值的哈希码; 与Short.hashCode()兼容。- 参数
-
value- 哈希值 - 结果
-
short值的哈希码值。 - 从以下版本开始:
- 1.8
-
equals
public boolean equals(Object obj)
将此对象与指定的对象进行比较。 当且仅当参数不是null并且是包含与此对象相同的short值的Short对象时,结果为true。- 重写:
-
equals在类Object - 参数
-
obj- 要与之比较的对象 - 结果
-
true如果对象相同; 否则为false。 - 另请参见:
-
Object.hashCode(),HashMap
-
compareTo
public int compareTo(Short anotherShort)
以数字方式比较两个Short对象。- Specified by:
-
compareTo,界面Comparable<Short> - 参数
-
anotherShort- 待比较的Short。 - 结果
-
值
0如果此Short是等于参数Short; 的值小于0,如果这Short在数值上小于该参数Short; 如果此Short在数值上大于参数Short(带符号的比较),则值大于0。 - 从以下版本开始:
- 1.2
-
compare
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 - 从以下版本开始:
- 1.7
-
compareUnsigned
public static int compareUnsigned(short x, short y)比较两个short值,以数值方式将值视为无符号。- 参数
-
x- 第一个short进行比较 -
y- 第二个short进行比较 - 结果
-
值
0如果x == y; 如果x < y为无符号值,则小于0值; 如果x > y为无符号值,则值大于0 - 从以下版本开始:
- 9
-
reverseBytes
public static short reverseBytes(short i)
返回通过反转指定的short值的二进制补码表示中的字节顺序获得的值。- 参数
-
i- 要反转其字节的值 - 结果
-
通过反转(或等效地,交换)指定的
short值中的字节获得的值。 - 从以下版本开始:
- 1.5
-
toUnsignedInt
public static int toUnsignedInt(short x)
通过无符号转换将参数转换为int。 在无符号转换到int,所述的高阶16个比特int是零和低阶16个比特都等于的比特short参数。 因此,零和正short值映射到数值相等的int值,负short值映射到等于输入加2 16的int值。- 参数
-
x- 要转换为无符号的值int - 结果
-
该参数通过无符号转换转换为
int - 从以下版本开始:
- 1.8
-
toUnsignedLong
public static long toUnsignedLong(short x)
通过无符号转换将参数转换为long。 在一个无符号转换为long,所述的高阶48个比特long是零和低阶16个比特都等于的比特short参数。 因此,零和正short值映射到数值相等的long值,负short值映射到等于输入加2 16的long值。- 参数
-
x- 要转换为无符号的值long - 结果
-
该参数通过无符号转换转换为
long - 从以下版本开始:
- 1.8
-
-