Converting a Primative byte array to a Byte array object

Discussion in 'Java' started by Kirby, Oct 6, 2004.

  1. Kirby

    Kirby Guest

    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
     
    Kirby, Oct 6, 2004
    #1
    1. Advertising

  2. Kirby

    andreas Guest


    >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
     
    andreas, Oct 6, 2004
    #2
    1. Advertising

  3. "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 = 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];
    }
     
    Boudewijn Dijkstra, Oct 6, 2004
    #3
  4. Kirby

    Kirby Guest

    Thanks you both for your help
     
    Kirby, Oct 8, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Earl Teigrob
    Replies:
    4
    Views:
    502
    Earl Teigrob
    May 19, 2004
  2. MattC
    Replies:
    4
    Views:
    3,911
    Thomas Hawtin
    Dec 30, 2005
  3. cryptogirl
    Replies:
    5
    Views:
    24,847
    cryptogirl
    Feb 25, 2006
  4. Replies:
    16
    Views:
    531
    James Kanze
    Oct 1, 2007
  5. Peter Michaux
    Replies:
    1
    Views:
    96
    Richard Cornford
    Oct 30, 2006
Loading...

Share This Page