因此我有一个字符串的字节值。例如通过:以Java的值初始化一个字节数组?
String str="Test String";
System.out.println(str.getBytes());
这使我:
[[email protected]
我可以使用该用于初始化字节阵列,例如:
byte[] bytes=new bytes("[[email protected]");
或什么?
因此我有一个字符串的字节值。例如通过:以Java的值初始化一个字节数组?
String str="Test String";
System.out.println(str.getBytes());
这使我:
[[email protected]
我可以使用该用于初始化字节阵列,例如:
byte[] bytes=new bytes("[[email protected]");
或什么?
不,这是班级名称([B
是byte[]
),散列码(1339a0dc
是十六进制的散列码)。哈希不能被逆转,因为它们不是bijective。
为什么打印这个?因为您使用的是隐式toString()
。这:
System.out.println(str.getBytes());
被编译器翻译成这样:
System.out.println(str.getBytes().toString());
因为System.out.println()
需要String
作为参数,因此隐式转换在这里制造。
所以你使用的是默认Object#toString()
实现,正如我以前(更多详情in the documentation)
getBytes
返回byte
阵列解释其工作原理。所以你可以这样做:
byte[] bytes = str.getBytes();
直接。
[[email protected]
只是一个表示为String的对象引用,它不是实际的字节数组