问题描述
嘿,我想弄清楚 [B@ 前缀在 Java 中的含义. 当我尝试打印字节数组时,它们会出现.但是,大小为 32 和大小为 4 的字节数组在长度上是相同的.总是[@B1234567".
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".
这是什么?此外,它们具有仅打印十六进制值的属性.我知道它不能只是二进制打印,因为会出现随机扩展的 ascii 字符.
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.
这是一个 byte[] 到 byte[] 哈希表映射打印的示例,其中映射由冒号分隔,这些是 4 字节键和 32 字节元素的字节数组.
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.
[B@1ef9157:[B@1f82982
[B@181ed9e:[B@16d2633
[B@27e353:[B@e70e30
[B@cb6009:[B@154864a
[B@18aaa1e:[B@3c9217
[B@20be79:[B@9b42e6
[B@16925b0:[B@14520eb
[B@8ee016:[B@1742700
[B@1bfc93a:[B@acb158
[B@107ebe1:[B@1af33d6
[B@156b6b9:[B@17431b9
[B@139b78e:[B@16c79d7
[B@2e7820:[B@b33d0a
[B@82701e:[B@16c9867
[B@1f14ceb:[B@89cc5e
[B@da4b71:[B@c837cd
[B@ab853b:[B@c79809
[B@765a16:[B@1ce784b
[B@1319c:[B@3bc473
推荐答案
您正在查看对象 ID,而不是内容的转储.
You're looking at the object ID, not a dump of the contents.
- [ 表示数组.
- B 表示字节.
- @ 将类型与 ID 分开.
- 十六进制数字是对象 ID 或哈希码.
- 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.
这里是完整的列表:
- B - 字节
- C - 字符
- D - 双倍
- F - 浮动
- I - int
- J - 长
- L***fully-qualified-class*;** -
L
和之间;
是完整的类名,使用/
作为包之间的分隔符(例如,Ljava/lang/String;
) - S - 短
- Z - 布尔值
- [ - 数组的每个维度一个
[
- (***argument types*)***return-type* - 方法签名,例如
(I)V
,附加伪类型为V
用于 void 方法
- 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 ofV
for void method
这篇关于Java:“[B@1ef9157"背后的语法和含义?二进制/地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!