Converting a Primative byte array to a Byte array object

K

Kirby

I have a primative byte array I wish to convert to a Byte array object.
So I want to convert from byte[] to Byte[]
Can somebody please suggest a way.

Thanks for your help.

Kirby
 
A

andreas

I have a primative byte array I wish to convert to a Byte array object.
So I want to convert from byte[] to Byte[]
Can somebody please suggest a way.

Thanks for your help.

Kirby

Byte[] array2 = new Byte[array1.length];
for(int i=0;i<array1.length;i++){
array2 = new Byte(array1);
}

i didn't run/test the code. but something like this should do it.

andreas
 
B

Boudewijn Dijkstra

andreas said:
I have a primative byte array I wish to convert to a Byte array
object.
So I want to convert from byte[] to Byte[]
Can somebody please suggest a way.

Thanks for your help.

Kirby

Byte[] array2 = new Byte[array1.length];
for(int i=0;i<array1.length;i++){
array2 = new Byte(array1);
}

i didn't run/test the code. but something like this should do it.


If you have many (equal) entries, I would suggest the following instead:

final Byte[] cache = new Byte[256];
for(int i = 0; i < 256; i++) {
cache = new Byte((byte) i);
}
Byte[] array2 = new Byte[array1.length];
for(int i = 0; i < array1.length; i++) {
array2 = cache[array1 & 0xFF];
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top