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

Posted on

Problem :

Hey, I’m trying to figure out what the [B@ prefix means in java. They come out when I attempt to print byte arrays. However, byte arrays of size 32 and size 4 are identical in length. Always “[@B1234567”.

What is this? Also, they have the property of only printing hex values. I know it can’t just be a binary print because random extended ascii chars would appear.

Here is an example of a byte[] to byte[] hashtable mapping print, where mappings are separated by a colon, and these are byte arrays of 4-byte keys and 32-byte elements.


Solution :

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 };

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

[B@ means “byte array”. Other primitive array types have different prefixes:

class Test
    public static void main(String [] args)
        byte[] b = new byte[0];
        int[] i = new int[0];
        char[] c = new char[0];
        long[] l = new long[0];
        double[] d = new double[0];
        float[] f = new float[0];
        short[] s = new short[0];        




Non-primitive types include the type name after [L for instance:


If you want to print the contents of a byte array as hex, here’s some code to help you:

class Test
    public static void main(String [] args)
        byte[] b = new byte[] { (byte) 0xf3, (byte) 0xf1, (byte) 0x7f };

    private static final char[] HEX_DIGITS = "0123456789abcdef".toCharArray();
    public static String toHex(byte[] bytes)
        char[] c = new char[bytes.length*2];
        int index = 0;
        for (byte b : bytes)
            c[index++] = HEX_DIGITS[(b >> 4) & 0xf];
            c[index++] = HEX_DIGITS[b & 0xf];
        return new String(c);

The default toString() implementation is the class name, followed by ‘@’, followed by the object’s hash code (in hexadecimal).

The default hash code, in turn, is “typically implemented by converting the internal address of the object into an integer”. In practice, the Sun JVM uses the address of an object handle as input to generate the default hash code.

In the case of primitive types (int, char, etc.) or array types like byte[], naming rules defined in the Java Virtual Machine Specification for field descriptors are used. According to those rules, one ‘[‘ indicates an array of one dimension, while ‘B’ indicates a component type of byte.

I suspect, though I don’t know, that the hex strings are representations of the instances’ addresses in memory, and probably have little to do with the lengths of the arrays. Can you clarify your question?

It worth noting that equals() comes from Object, so that if a.equals(b) then a == b. i.e. if you have two byte arrays which contain the same data, they are not equals() and will not match keys in a Hashtable, HashXxxx

I had this problem when I used csv input component. After a lot of hours I discovered that the values are bytes. I resolved this selecting Yes for the parameter Binary to normal on Select Value component.

Leave a Reply

Your email address will not be published. Required fields are marked *