my dog learned polymorphism*
The moose likes Java in General and the fly likes byte array to String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "byte array to String" Watch "byte array to String" New topic

byte array to String

Suresh Ray
Ranch Hand

Joined: Feb 21, 2000
Posts: 55
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.
// 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?
Carl Trusiak

Joined: Jun 13, 2000
Posts: 3340
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

I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
I agree. Here's the link:
subject: byte array to String
Similar Threads
Converting String to Byte[] array
Attribute value in the ldap node
how to convert byte [] to String?
Convert String to primitive int without using Wrapper classes
How to convert binary octet string into byte array for writing into socket