文章目錄
1 Byte 類方法
- 返回類型標 * 的是重點方法
1.1 toString —— 將 Short 轉爲 String
返回類型 | 方法名 | 描述 |
---|---|---|
static String | toString(byte b) | Integer.toString((int)s, 10) |
String | toString() | Integer.toString((int)value) |
1.2 parseByte —— 將 String 轉爲 byte
返回類型 | 方法名 | 描述 |
---|---|---|
static byte | parseByte(String s) | parseByte(s, 10) |
static byte | parseByte(String s, int radix) | Integer.parseInt(s, radix),如果返回的 int 值 不在 byte 的範圍內,則報錯 |
1.3 valueOf —— 將 String、short 轉爲 Byte
返回類型 | 方法名 | 描述 |
---|---|---|
static Byte | valueOf(String s) | valueOf(s, 10) |
static Byte | valueOf(String s, int radix) | valueOf(parseByte(s, radix)) |
static Byte | valueOf(byte b) | 直接走 cache |
1.4 hashcode/compare
返回類型 | 方法名 | 描述 |
---|---|---|
int | hashCode() | Byte.hashCode(value) |
static int | hashCode(byte value) | (int)value |
int | compareTo(Byte anotherByte) | compare(this.value, anotherByte.value) |
static int | compare(byte x, byte y) | x - y,這個返回的不是固定的 -1,0,1 |
1.5 toUnsignedInt/toUnsignedLong
返回類型 | 方法名 | 描述 |
---|---|---|
static int | toUnsignedInt(byte x) | ((int) x) & 0xff |
static long | toUnsignedLong(byte x) | ((long) x) & 0xffL |
1.6 構造函數 Byte(String)
- 內部調用 parseByte(s,10)
- 推薦使用 Byte.valueOf(s),因爲這樣返回的肯定是 cache
參考
jdk1.8_171