Short 基本數據類型short 的包裝類
Short 類型的對象包含一個 short 類型的字段
原文地址:
[五]基礎數據類型之Short詳解
屬性簡介
值為 215-1 的常量,它表示 short 類型能夠表示的最大值 public static final short MAX_VALUE = 32767; |
值為 -215 的常量,它表示 short 類型能夠表示的最小值 public static final short MIN_VALUE = -32768; |
用來以二進制補碼形式表示 short 值的比特位數 public static final int SIZE = 16; |
二進制補碼形式表示 short 值的字節數 public static final int BYTES = SIZE / Byte.SIZE; |
表示基本類型 short 的 Class 實例 public static final Class<Short> TYPE = (Class<Short>) Class.getPrimitiveClass("short"); |
構造方法
照常兩種形式
常用方法
比較
static int compare(short x, short y)
靜態方法
x<y 小於0
x=y 等於0
x>y 大於0
![]() |
int compareTo(Short anotherShort) 實例方法 調用靜態方法比較兩個對象的值 ![]() |
parseXXX系列
parseShort系列依賴Integer.parseInt
valueOf系列
static Short valueOf(short s)![]() |
static Short valueOf(String s, int radix)![]() |
static Short valueOf(String s)![]() |
XXXValue系列
類似 Integer和Long Byte Short也有提供XXXValue系列方法,原理也跟他們類似 全部都是強轉 |
byteValue()
shortValue()
intValue()
longValue()
floatValue()
doubleValue()
|
toUnsignedXXX 系列
toString 系列
static String toString(short s)![]() |
String toString()![]() |
static int toUnsignedInt(short x) ![]() |
static long toUnsignedLong(short x)![]() |
equals
hashCode
Short的hashcode 也是直接返回值
其他方法
Short提供了reverseBytes(short) 方法
Short雖然比Byte稍微提供的支持多一點點,但是也很少
有些方法也是依賴於Integer