Java: Syntax and meaning behind “[B@1ef9157”? Binary/Address?

You’re looking at the object ID, not a dump of the contents.

  • The [ means array.
  • The B means byte.
  • The @ separates the type from the ID.
  • The hex digits are an object ID or hashcode.

If the intent is to print the contents of the array, there are many ways. For example:

byte[] in = new byte[] { 1, 2, 3, -1, -2, -3 };
System.out.println(byteArrayToString(in));

String byteArrayToString(byte[] in) {
    char out[] = new char[in.length * 2];
    for (int i = 0; i < in.length; i++) {
        out[i * 2] = "0123456789ABCDEF".charAt((in[i] >> 4) & 15);
        out[i * 2 + 1] = "0123456789ABCDEF".charAt(in[i] & 15);
    }
    return new String(out);
}

A complete list of the type nomenclature can be found in the JNI documentation.

Here is the entire list:

  • B – byte
  • C – char
  • D – double
  • F – float
  • I – int
  • J – long
  • L***fully-qualified-class*;** – between an L and a ; is the full class name, using / as the delimiter between packages (for example, Ljava/lang/String;)
  • S – short
  • Z – boolean
  • [ – one [ for every dimension of the array
  • (***argument types*)***return-type* – method signature, such as (I)V, with the additional pseudo-type of V for void method

Leave a Comment