1

我试过:

int amount = 5;
String amountStr = "0x0" + amount;
byte newByte = Byte.parsByte(amountStr);

但我明白了java.lang.NumberFormatException: For input string: "0x05"

4

1 回答 1

5

如果要解析字符串,请使用Byte#decode

byte newByte = Byte.decode(amountStr);

否则,您可以直接转换它(如评论中所述)。

于 2012-04-19T17:14:57.827 回答