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 に答える