Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

byte array to String

 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
How do we convert a primitive byte array to a String or a String array? I tried first, to convert the byte array to "Byte" array, but was unable to do it. My idea was to get the values stored in the Byte array and use this to convert into String or String array. I would appreciate if someone can help with this.
Code:
// data variable gets populated with byte values
byte[] data = e.getEventData();
// declare a Byte object array
Byte[] data1;
Question: How do we assign each value of the primitive byte values to the corresponding Byte values. Byte class has a constructor which takes in a byte value, but how do we recursively populate the Byte array with the byte primitive values?
Thanks
Suresh
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You create a new String object with it
// data variable gets populated with byte values
byte[] data = e.getEventData();
//create a new String object
String s = new String(data);
Hope this helps
reply
    Bookmark Topic Watch Topic
  • New Topic