"andreas" <> schreef in bericht
news:41639e8b$...
>
> > 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[i] = new Byte(array1[i]);
> }
>
> 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[i] = new Byte((byte) i);
}
Byte[] array2 = new Byte[array1.length];
for(int i = 0; i < array1.length; i++) {
array2[i] = cache[array1[i] & 0xFF];
}
|