Java Question: Taking Input String - Converting to byte[] - now I need to convert byte[] back to the input string?

I have an input str, that I convert to a byte[], and now i need to convert the byte[] back to the original input string.  How is that best accomplished?
Who is Participating?
String has a constructor for that

byte[] bytes = s.getBytes();
String s = new String(bytes);

or if a different encoding is used

String s = new String(bytes, charset)
String s = new String(bytes)
mtitania, can you tell me why you accepted an answer that was just a repeat of mine?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.