简体   繁体   中英

How to turn byte array into string array without any conversion

I have a byte array. I need to show its bytes on screen. How can I turn the bytes into a string representation without any conversion?

*By conversion, in this context I mean not decoding it into ASCII or any other equivalent encoding system

So for instance, if I have:

byte[] a = { 0x3F, 0x2C, 0x6A };

I'd like results like this:

String[] b = { "3F", "2C", 6A"};
byte[] a = { 0x3F, 0x2C, 0x6A };
String[] s = new String[a.length];
for (int i=0; i<a.length; i++) {
  s[i] = String.format("%02X", a[i]);
}
// s => ["3F", "2C", "6A"]

Give this a try

Byte[] a = {31,22,62}; 

System.out.println(Arrays.deepToString(a));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM