Deciphering the Meaning Behind "[B@1ef9157" in Java
When working with Java, developers may encounter peculiar prefixes such as "[B@1ef9157" upon attempting to print byte arrays. While these strings may appear cryptic, they hold significant information about the array's structure and contents.
Composition of the Prefix
The prefix "[B@1ef9157" can be broken down into the following components:
Interpreting the Prefix
The prefix alone does not reveal the contents of the byte array. It merely signifies that the object is a byte array and provides its unique identifier. The actual values stored in the array are not displayed in this format.
Printing the Array Contents
To view the actual contents of the byte array, various methods are available. One technique involves converting the byte values to hexadecimal characters:
<code class="java">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); }</code>
Additional Information
For a comprehensive list of type nomenclatures used in Java, refer to the JNI documentation. The following table summarizes the common types:
Type | Representation | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Byte | B | ||||||||||||||||||||||||
Character | C | ||||||||||||||||||||||||
Double | D | ||||||||||||||||||||||||
Float | F | ||||||||||||||||||||||||
Integer | I | ||||||||||||||||||||||||
Long | J | ||||||||||||||||||||||||
Class | L*fully-qualified-class*;; | ||||||||||||||||||||||||
Short | S | ||||||||||||||||||||||||
Boolean | Z | ||||||||||||||||||||||||
Array | [ | ||||||||||||||||||||||||
Method Signature | (
|
The above is the detailed content of What does \'[B@1ef9157\' mean when printing byte arrays in Java?. For more information, please follow other related articles on the PHP Chinese website!