Java 8+

Use String.join():

String str = String.join(",", arr);

Note that arr can also be any Iterable (such as a list), not just an array.

If you have a Stream, you can use the joining collector:

Stream.of("a", "b", "c")
      .collect(Collectors.joining(","))

Legacy (Java 7 and earlier)

StringBuilder builder = new StringBuilder();
for(String s : arr) {
    builder.append(s);
}
String str = builder.toString();

Alternatively, if you just want a "debug-style" dump of an array:

String str = Arrays.toString(arr);

Note that if you're really legacy (Java 1.4 and earlier) you'll need to replace StringBuilder there with StringBuffer.

Android

Use TextUtils.join():

String str = TextUtils.join(",", arr);

General notes

You can modify all the above examples depending on what characters, if any, you want in between strings.

DON'T use a string and just append to it with += in a loop like some of the answers show here. This sends the GC through the roof because you're creating and throwing away as many string objects as you have items in your array. For small arrays you might not really notice the difference, but for large ones it can be orders of magnitude slower.

Answer from Michael Berry on Stack Overflow
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java string โ€บ array to string conversions
Array to String Conversions | Baeldung
September 16, 2026 - Sometimes we need to convert an array of strings or integers into a string, but unfortunately, there is no direct method to perform this conversion.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ arrays-tostring-in-java-with-examples
Arrays.toString() in Java with Examples - GeeksforGeeks
Converts an array into a string containing all its elements. For object arrays with nested arrays, it prints memory references instead of actual values. For nested arrays, Arrays.deepToString() should be used to get full content representation.
Published: April 14, 2026
Discussions

How to convert an int array to String with toString method in Java - Stack Overflow
I took this code out of bigger and more complex code, but I can add it if needed. But this should give general information. I am looking for output, like in Oracle's documentation: The string representation consists of a list of the array's elements, enclosed in square brackets ("[]"). Adjacent elements are separated by the characters ", " (a comma followed by a space). ... import java... More on stackoverflow.com
๐ŸŒ stackoverflow.com
string to string array conversion in java - Stack Overflow
I have a string = "name"; I want to convert into a string array. How do I do it? Is there any java built in function? Manually I can do it but I'm searching for a java built in function. I want an... More on stackoverflow.com
๐ŸŒ stackoverflow.com
[University Programming (java)] Converting an array to string?
thanks all!! got it working More on reddit.com
๐ŸŒ r/HomeworkHelp
3
2
April 1, 2014
using the toString method...how would I pass an array through?
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 - best also formatted as code block 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. 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/markdown editor: 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/learnjava
11
4
May 26, 2022
Top answer
1 of 14
642

Java 8+

Use String.join():

String str = String.join(",", arr);

Note that arr can also be any Iterable (such as a list), not just an array.

If you have a Stream, you can use the joining collector:

Stream.of("a", "b", "c")
      .collect(Collectors.joining(","))

Legacy (Java 7 and earlier)

StringBuilder builder = new StringBuilder();
for(String s : arr) {
    builder.append(s);
}
String str = builder.toString();

Alternatively, if you just want a "debug-style" dump of an array:

String str = Arrays.toString(arr);

Note that if you're really legacy (Java 1.4 and earlier) you'll need to replace StringBuilder there with StringBuffer.

Android

Use TextUtils.join():

String str = TextUtils.join(",", arr);

General notes

You can modify all the above examples depending on what characters, if any, you want in between strings.

DON'T use a string and just append to it with += in a loop like some of the answers show here. This sends the GC through the roof because you're creating and throwing away as many string objects as you have items in your array. For small arrays you might not really notice the difference, but for large ones it can be orders of magnitude slower.

2 of 14
106

Use Apache commons StringUtils.join(). It takes an array, as a parameter (and also has overloads for Iterable and Iterator parameters) and calls toString() on each element (if it is not null) to get each elements string representation. Each elements string representation is then joined into one string with a separator in between if one is specified:

String joinedString = StringUtils.join(new Object[]{"a", "b", 1}, "-");
System.out.println(joinedString);

Produces:

a-b-1
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ how-to-convert-an-array-to-string-in-java
How to Convert an Array to String in Java? - GeeksforGeeks
July 12, 2025 - The most simple method is the Arrays.toString() to convert an array to a string. ... // Java Program to convert an array to a string // using Arrays.toString() method import java.io.*; import java.util.Arrays; class GFG { public static void ...
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ array to string in java
Array to String In Java | Scaler Topics
June 2, 2024 - In Java programming language, an array is a data structure that stores the same type of value in a contiguous memory location which we can access using the index, whereas a string is an object that stores a sequence of characters, so there can be some situation where we want to convert an array to string, so for this we have some methods like toString, StringBuilder append, etc.
๐ŸŒ
CodeGym
codegym.cc โ€บ java blog โ€บ strings in java โ€บ array to string in java
Array to String in Java
November 27, 2023 - Sometimes, you might need a bit more control over how you convert the array to string. Maybe you're not a fan of those square brackets, or you need a specific separator between elements. In such cases, Java's String.join() and good old loops come to the rescue.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ string-arrays-in-java
String Arrays in Java - GeeksforGeeks
October 2, 2025 - A String Array in Java is an array that stores string values. In this article, we will learn the concepts of String Arrays in Java including declaration, initialization, iteration, searching, sorting, and converting a String Array to a single string.
Find elsewhere
๐ŸŒ
DigitalOcean
digitalocean.com โ€บ community โ€บ tutorials โ€บ java-string-array-to-string
Java String Array to String | DigitalOcean
August 3, 2022 - From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.
๐ŸŒ
Microsoft Learn
learn.microsoft.com โ€บ en-us โ€บ dotnet โ€บ api โ€บ java.util.arrays.tostring
Arrays.ToString Method (Java.Util) | Microsoft Learn
The string representation consists ... ", " (a comma followed by a space). Elements are converted to strings as by String.valueOf(int)....
๐ŸŒ
Hostman
hostman.com โ€บ tutorials โ€บ converting-arrays-and-strings-in-java
Java Array to String and String to Array Conversion Guide
In Java, strings are treated as objects, and the language furnishes a robust set of methods for the manipulation of textual information. This tutorial provides a comprehensive guide on how to convert arrays to strings and strings to arrays in Java.
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ how-to-convert-an-array-to-string-in-java
How to convert an array to string in java?
March 11, 2026 - import java.util.Arrays; public class ArrayToString { public static void main(String args[]) throws Exception { int[] myArray = {23, 93, 56, 92, 39}; String str = Arrays.toString(myArray); System.out.println(str); } } [23, 93, 56, 92, 39] Nikitha N ยท Updated on: 2026-03-11T22:50:41+05:30 ยท
๐ŸŒ
Reddit
reddit.com โ€บ r/homeworkhelp โ€บ [university programming (java)] converting an array to string?
r/HomeworkHelp on Reddit: [University Programming (java)] Converting an array to string?
April 1, 2014 -

This is driving me nuts:

Array is as follows:

String[] myarray = new String[5];
myarray[0] = {"foo"}
myarray[1] = {"."}
myarray[2] = {"this"}
myarray[3] = {"."}
myarray[4] = {"bar"}

Im trying to convert it to a string using Arrays.toString but its not working:

String mystring = new String(Arrays.toString(myarray));
System.out.println(mystring); 

this prints out: [foo, ., this, ., bar]

why?

i just want: foo.this.bar

I also don't understand the methods on stackexchange

๐ŸŒ
Codemia
codemia.io โ€บ home โ€บ knowledge hub โ€บ convert array of strings into a string in java
Convert array of strings into a string in Java | Codemia
January 26, 2025 - Introduced in Java 8, String.join() is a convenient method to concatenate an array of String objects in a single line. This method takes the delimiter and an Iterable (e.g., an array or a list) and joins each element of the iterable separated ...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ java โ€บ util โ€บ arrays_tostring_int.htm
Java.util.Arrays.toString(int[ ]) Method
The java.util.Arrays.toString(int[]) method returns a string representation of the contents of the specified int array. The string representation consists of a list of the array's elements, enclosed in square brackets ("[]").
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ java_howto_string_to_array.asp
Java How To Convert a String to an Array
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... There are many ways to convert a string to an array.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjava โ€บ using the tostring method...how would i pass an array through?
r/learnjava on Reddit: using the toString method...how would I pass an array through?
May 26, 2022 -

Every tutorial I see on YouTube shows how to pass 1,2, or 3 individual variables through methods using toString.

How do I do it if I want to pass an array...like a simple array of 10 numbers.

I want one method to set the array with the 10 numbers (which I know how to do with a for loop) but rather than print it in a separate for loop in the same method...I want to use toString and thus produce those 10 numbers in that separate method.

How do I go about doing that?

Top answer
1 of 2
3
Arrays.toString(yourArray) If you want to customise values, you can abuse the Stream API to do this. Stream .of(someArray) .map(item -> "blahblah" + item + "blahblah") .collect(Collectors.joining(", ", "[", "]")); Of course, it is slightly more efficent to use the primitive stream wrappers if your array contains primitives, as it can avoid an additional boxing operation. IntStream .of(someArray) .mapToObj(i -> Integer.toString(i / 2)) .collect(Collectors.joining(", ", "[", "]")); ...as an example. For performance critical code where Arrays.toString does not do what you need, then using a vanilla for-loop and a StringBuilder is going to be significantly faster than streams, remember. Personally I wish Java would update the built in toString for Arrays to call Arrays.toString automatically, as there is practically zero use for the default array.toString. The only useful thing it provides is easily accessible in a cleaner way through reflection and methods on java.lang.System, so no code should even be relying on it. That would also make the behaviour similar to how Collection classes act by default, but it is what it is.
2 of 2
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 - best also formatted as code block 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. 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/markdown editor: 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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ convert-character-array-to-string-in-java
How to Convert Character Array to String in Java? - GeeksforGeeks
July 15, 2025 - With the introduction of streams in java8, we straight away use Collectors in streams to modify our character input array elements and later uses joining() method and return a single string and print it.