1

I have the following code :

byte[] data = "String".getBytes();
System.out.println("data: " + data);

and on some runs I get different output values, e.g.

data: [B@4769baee
data: [B@308c3eb8
data: [B@7b3a4cdc

Why this is happening ?

Patryk
  • 22,602
  • 44
  • 128
  • 244
  • that's not the actual value, it's the objects 'name' – Harry Blargle Jun 01 '14 at 21:47
  • 1
    When you print out a byte array like that, you actually call the `toString()` method of array. Unfortunately, that does not print the contents of the array, but the hashcode of the instance http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#toString%28%29 Use `Arrays.toString(data)` instead. – Zoltán Jun 01 '14 at 21:52

0 Answers0