我有一个由字节数组表示的整数。
byte[] result = getResult();
resultInt1 = Integer.parseInt(Bytes.toString(result));//1
resultInt2 = Integer.parseInt(result.toString());//2
第一种方式一切正常,但在第二种方式中,我发现NumberFormatException。
这两种方法有什么区别?
数组不会覆盖toString()
。
因此,bytes.toString()
不返回任何有意义的内容;相反,它将返回类似[B@18c28a
的内容。([B
是byte
数组的内部表示)