Your byte array must have some encoding. The encoding cannot be ASCII if you've got negative values. Once you figure that out, you can convert a set of bytes to a String using:

byte[] bytes = {...}
String str = new String(bytes, StandardCharsets.UTF_8); // for UTF-8 encoding

There are a bunch of encodings you can use, look at the supported encodings in the Oracle javadocs.

Answer from omerkudat on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-convert-byte-array-to-string
Java Program to Convert Byte Array to String - GeeksforGeeks
We can convert the byte array to String for the ASCII character set without even specifying the character encoding. The idea is to pass the byte[] to the string. It is as shown in the below example which is as follows: ... // Java Program to Convert Byte Array to String // Without character encoding // Importing required classes import java.io.IOException; import java.util.Arrays; // Main class class GFG { // Main driver method public static void main(String[] args) throws IOException { // Getting bytes from the custom input string // using getBytes() method and // storing it in a byte array byte[] bytes = "Geeksforgeeks".getBytes(); System.out.println(Arrays.toString(bytes)); // Creating a string from the byte array // without specifying character encoding String string = new String(bytes); // Printing the string System.out.println(string); } }
Published: July 23, 2025
Discussions

Java Byte Array to String to Byte Array - Stack Overflow
To add to what is otherwise a correct (albeit incomplete) answer: 1) Any byte[] array being converted into a String in Java should specify the character-set. Is the byte[] array UTF-8 or something else? Not being specific or knowing what it is can create bugs. More on stackoverflow.com
🌐 stackoverflow.com
How do you convert an "Byte array to string" text array back to normal text?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
7
4
February 24, 2021
converting large byte array back to string
If you need it as String, why even have a byte array in the first place? Please, go into details of your use case and your reasoning for the byte array. This would probably help us. You could use a Scanner over the file and use nextByte with the delimiter set right to read in the values and directly throw them in the byte array. More on reddit.com
🌐 r/javahelp
12
2
August 21, 2025
Java help with byte arrays
Concatenate the strings together first? More on reddit.com
🌐 r/learnprogramming
19
2
November 13, 2016
🌐
DigitalOcean
digitalocean.com › community › tutorials › string-byte-array-java
String to byte array, byte array to String in Java | DigitalOcean
From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.
🌐
Mkyong
mkyong.com › home › java › how to convert byte[] array to string in java
How to convert byte[] array to String in Java | mkyong.com
January 18, 2022 - In Java, we can use new String(bytes, StandardCharsets.UTF_8) to convert a byte[] to a String. // string to byte[] byte[] bytes = "hello".getBytes(StandardCharsets.UTF_8); // byte[] to string String s =
Top answer
1 of 12
286

You can't just take the returned string and construct a string from it... it's not a byte[] data type anymore, it's already a string; you need to parse it. For example :

String response = "[-47, 1, 16, 84, 2, 101, 110, 83, 111, 109, 101, 32, 78, 70, 67, 32, 68, 97, 116, 97]";      // response from the Python script

String[] byteValues = response.substring(1, response.length() - 1).split(",");
byte[] bytes = new byte[byteValues.length];

for (int i=0, len=bytes.length; i<len; i++) {
   bytes[i] = Byte.parseByte(byteValues[i].trim());     
}

String str = new String(bytes);

** EDIT **

You get an hint of your problem in your question, where you say "Whatever I seem to try I end up getting a byte array which looks as follows... [91, 45, ...", because 91 is the byte value for [, so [91, 45, ... is the byte array of the string "[-45, 1, 16, ..." string.

The method Arrays.toString() will return a String representation of the specified array; meaning that the returned value will not be a array anymore. For example :

byte[] b1 = new byte[] {97, 98, 99};

String s1 = Arrays.toString(b1);
String s2 = new String(b1);

System.out.println(s1);        // -> "[97, 98, 99]"
System.out.println(s2);        // -> "abc";

As you can see, s1 holds the string representation of the array b1, while s2 holds the string representation of the bytes contained in b1.

Now, in your problem, your server returns a string similar to s1, therefore to get the array representation back, you need the opposite constructor method. If s2.getBytes() is the opposite of new String(b1), you need to find the opposite of Arrays.toString(b1), thus the code I pasted in the first snippet of this answer.

2 of 12
140
String coolString = "cool string";

byte[] byteArray = coolString.getBytes();

String reconstitutedString = new String(byteArray);

System.out.println(reconstitutedString);

That outputs "cool string" to the console.

It's pretty darn easy.

🌐
Javatpoint
javatpoint.com › how-to-convert-byte-array-to-string-in-java
How to convert byte array to String in Java?
How to Convert byte Array to String in Java with oops, string, exceptions, multithreading, collections, jdbc, rmi, fundamentals, programs, swing, javafx, io streams, networking, sockets, classes, objects etc,
🌐
Coderanch
coderanch.com › t › 446922 › java › convert-byte-array-string-array
How to convert byte array to string array ? (I/O and Streams forum at Coderanch)
From client side I am sending string array which by default get converted into byte array(client is in J2ME). On server side I receive the data in byte array format.
Find elsewhere
🌐
Crunchify
crunchify.com › java j2ee tutorials › in java how to convert byte[] array to string and string to byte[]?
In Java How to convert Byte[] Array To String and String to Byte[]? • Crunchify
December 28, 2025 - We will manipulate String and byte[] 5 different ways. ... toString() function on String object wont return actual string but only HashValue. Look for all comments mentioned in below Java program. package crunchify.com.tutorials; import ...
🌐
How to do in Java
howtodoinjava.com › home › java array › convert byte[] to string and vice-versa
Convert byte[] Array to String in Java - HowToDoInJava
December 15, 2022 - Until it is absolute necessary, DO NOT convert between string and byte array. They both represent different data; and are there to serve specific purposes i.e. strings are for text, byte[] is for binary data.
🌐
Attacomsian
attacomsian.com › blog › java-convert-byte-array-to-string
How to convert a byte array to a string in Java
October 29, 2022 - Conversion between byte array and ... etc. The simplest way to convert a byte array to a string is to use the String class constructor with byte[] as an argument:...
🌐
Techie Delight
techiedelight.com › home › java › convert a byte array to a string in java
Convert a byte array to a String in Java | Techie Delight
July 7, 2026 - We can convert the byte array to String for the ASCII character set without even specifying the character encoding. The idea is to pass the byte[] to the String constructor.
🌐
Reddit
reddit.com › r/javahelp › how do you convert an "byte array to string" text array back to normal text?
r/javahelp on Reddit: How do you convert an "Byte array to string" text array back to normal text?
February 24, 2021 -

I got a string called abc, I got the bytes of abc and put them into the byte array named b, then i created a string which converts byte array b to string via Arrays.toString(b). This results in [97, 98, 99, 100, 101, 102, 103, 104, 105, 103, 104, 116].

How would you reverse this? (it's a seperate function).

Top answer
1 of 3
4
Try new String(b); This will convert it back to a regular string.
2 of 3
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
🌐
Coderanch
coderanch.com › t › 321766 › java › byte-array-String
byte array to String (Java in General forum at Coderanch)
Byte class has a constructor which ... values? Thanks Suresh ... 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...
🌐
Scaler
scaler.com › home › topics › convert byte array to string in java
Convert Byte Array to String in Java - Scaler Topics
May 4, 2023 - In this method we need to pass the byte[] as an argument to the string class constructor. Following is an example that displays the use of a string class constructor. ... Explanation In the above code, we have converted a string “Learn with Scalar” into a bytes array.
🌐
Blogger
javarevisited.blogspot.com › 2014 › 08 › 2-examples-to-convert-byte-array-to-String-in-Java.html
2 Examples to Convert Byte[] Array to String in Java
June 27, 2025 - In this article, we will learn how to convert byte[] to String in Java both by using JDK API and with the help of Guava and Apache commons. There are multiple ways to change byte array to String in Java, you can either use methods from JDK, or you can use open-source complementary APIs like Apache commons and Google Guava.
🌐
Centron
centron.de › startseite › string to byte array and byte array to string conversion in java
String to Byte Array and Byte Array to String Conversion in Java
February 5, 2025 - However if we provide Charset name, then we will have to either catch UnsupportedEncodingException exception or throw it. Better approach is to use StandardCharsets class introduced in Java 1.7 as shown below. ... That’s all the different ways to convert String to byte array in java.
🌐
Medium
medium.com › @ujjawalr › convert-byte-to-string-in-5-ways-in-java-28271e01e6b8
Convert byte[] to String in 5 ways in java | by Ujjawal Rohra | Medium
February 12, 2023 - Java String class has a constructor which takes a byte[] as argument and returns its string representation. Example, byte[] bytes = {72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100}; String str = new String(bytes); System.out.println(str); ...
🌐
Coderanch
coderanch.com › t › 658180 › java › Converting-Byte-Array-String
Converting Byte Array to String (Java in General forum at Coderanch)
November 21, 2015 - The constructor of the String class simply takes the byte array and copies it in binary to be treated as a string. No formatting is done. This is, of course, *not* what you want. You will need to loop through the six bytes, parse each byte to a two digit hexadecimal string, and add the delimiters ...
🌐
javaspring
javaspring.net › blog › convert-byte-array-to-string-java
Converting Byte Arrays to Strings in Java — javaspring.net
A byte array in Java is a sequence of 8-bit signed values. It is declared as byte[] and can be used to store various types of binary data. For example: byte[] byteArray = { 72, 101, 108, 108, 111 }; // Represents "Hello" in ASCII · A string in Java is an immutable sequence of characters.
🌐
Java Code Geeks
javacodegeeks.com › home › core java
2 Examples to Convert Byte[] array to String in Java
September 3, 2014 - In this article, we will learn how to convert byte[] to String in Java both by using JDK API and with the help of Guava and Apache commons. There are multiple ways to change byte array to String in Java, you can either use methods from JDK, or you can use open source complimentary APIs like Apache commons and Google Guava.