I've been implementing an Android app which communicates with a Java server, and they send byte arrays back and fourth. When I use Arrays.toString(byte[])
then everything works as expected, however this is not the case with printing to the console. Here I print a byte array to the console in Android:
Log.d("byte array test"" + new byte[]{109, 89, -47, 12, 80, -13, 27, -9, 1, 117, -128, -98, 31, 2, -79, -36, -38, 78, -88, 74, 78, 105, 8, -53, 63, -96, -126, 85, -63, -105, 96, 124});
Which produces the following output:
D/byte array test: [B@b4938b
On Java:
System.out.println( new byte[]{109, 89, -47, 12, 80, -13, 27, -9, 1, 117, -128, -98, 31, 2, -79, -36, -38, 78, -88, 74, 78, 105, 8, -53, 63, -96, -126, 85, -63, -105, 96, 124} "");
Which produces the following output:
[B@43556938
Can anyone explain why? To the best of my understanding, they're both strings, so they both should produce the same output. Encoding is the only reason I could think of a difference, but I don't have much experience with that, so I'm not sure.