Java的:语法和含义背后" [B @ 1ef9157"?二进制/地址? [英] Java: Syntax and meaning behind "[B@1ef9157"? Binary/Address?

查看:1034
本文介绍了Java的:语法和含义背后" [B @ 1ef9157"?二进制/地址?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出什么[B @ preFIX在java中的意思。他们出来的时候我试图打印字节数组。然而,尺寸32和尺寸4的字节数组的长度是相同的。总是[@ B1234567。

这是什么?此外,他们有只打印十六进制值的属性。我知道它不能只是一个二进制打印,因为随机扩展ASCII字符将会出现。

下面是一个byte []的例子为byte []哈希表映射打印,其中映射用冒号​​隔开,而这些都是4字节键和32个字节的元素字节数组。

  [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,而不是内容的转储。


  • [表示数组。

  • 表示字节。

  • @ 分离从ID类型。

  • 十六进制数字是对象ID或哈希code。

如果意图是打印数组的内容,有很多方法。例如:

 字节[] =中的新的字节[] {1,2,3,-1,-2,-3};
的System.out.println(byteArrayToString(在));字符串byteArrayToString(字节[]中){
    烧焦了[] =新的char [in.length * 2];
    的for(int i = 0; I< in.length;我++){
        出[我* 2] =0123456789ABCDEF.charAt((在[I]≥→4)及15);
        出[I * 2 + 1] =0123456789ABCDEF.charAt(在[1] - 放大器; 15);
    }
    返回新的String(出);
}

A <一个href=\"http://download.oracle.com/javase/6/docs/technotes/guides/jni/spec/types.html#wp16432\">complete类型命名列表可以在找到JNI文档

下面是整个列表:


  • - 字节

  • C - 焦

  • D - 双

  • ˚F - 浮动

  • - INT

  • Ĵ - 长

  • 完全合格级 - 一个→之间; 是完整的类名称,使用 / 作为包之间的分隔符(例如, Ljava /朗/字符串;

  • 取值 - 短

  • 以Z - 布尔

  • [ - 有一个 [为阵
  • 的每一个层面
  • 的参数类型 返回式的 - 方法签名,如 (我)V ,如果加上伪类型的V 的无效​​方法

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.

[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

解决方案

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
  • Lfully-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

这篇关于Java的:语法和含义背后&QUOT; [B @ 1ef9157&QUOT;?二进制/地址?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆