Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Converting a Primative byte array to a Byte array object

Reply
Thread Tools

Converting a Primative byte array to a Byte array object

 
 
Kirby
Guest
Posts: n/a
 
      10-06-2004
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
 
Reply With Quote
 
 
 
 
andreas
Guest
Posts: n/a
 
      10-06-2004

>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.

andreas


 
Reply With Quote
 
 
 
 
Boudewijn Dijkstra
Guest
Posts: n/a
 
      10-06-2004
"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];
}


 
Reply With Quote
 
Kirby
Guest
Posts: n/a
 
      10-08-2004
Thanks you both for your help
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
operator overloading for primative types PengYu.UT@gmail.com C++ 16 10-01-2007 08:40 AM
Setting a constructor's prototype property to a primative, array or function. Peter Michaux Javascript 1 10-30-2006 09:46 PM
converting a int array to a byte array cryptogirl Java 5 02-25-2006 03:38 PM
Taking the Contents of a File object and converting it to a byte array MattC Java 4 12-30-2005 08:21 PM
Setting a Custom Control Property that is an enumeration (or other non primative type) from aspx page Earl Teigrob ASP .Net 4 05-19-2004 06:55 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57