Using Java 8 you can do this in a very clean way:

String.join(delimiter, elements);

This works in three ways:

1) directly specifying the elements

String joined1 = String.join(",", "a", "b", "c");

2) using arrays

String[] array = new String[] { "a", "b", "c" };
String joined2 = String.join(",", array);

3) using iterables

List<String> list = Arrays.asList(array);
String joined3 = String.join(",", list);
Answer from skiwi on Stack Overflow
🌐
CodeGym
codegym.cc › java blog › strings in java › java string join() method
Java String join() Method
January 8, 2025 - Iterable which can be a list or array of elements, needs to be joined. It always returns a concatenated string of elements joined by the delimiter. import java.util.ArrayList; class Main { public static void main(String[] args) { ArrayList<String> arrayOfStrings = new ArrayList<>(); arrayOfStrings.add("Concatenating"); arrayOfStrings.add("the"); arrayOfStrings.add("array"); arrayOfStrings.add("list"); arrayOfStrings.add("elements"); arrayOfStrings.add("with"); arrayOfStrings.add("space"); arrayOfStrings.add("as"); arrayOfStrings.add("delimiter"); // joining arrayList with space between them as delimiter String joinedStr = String.join(" ", arrayOfStrings); System.out.println(joinedStr); } }
🌐
Baeldung
baeldung.com › home › java › java array › join array of primitives with separator in java
Join Array of Primitives with Separator in Java | Baeldung
January 8, 2024 - When joining our char array with this method, we must first wrap the char array into CharBuffer and then project it to char again. This is because the chars() method returns a Stream of int values.
🌐
How to do in Java
howtodoinjava.com › home › java array › join string array in java with comma or any separator
Join String Array in Java with Comma or Any Separator
3 weeks ago - The shortest way to join a String array in Java is String.join(“,”, array), which returns one String with the separator between every two elements and none after the last.
🌐
W3Schools
w3schools.com › java › ref_string_join.asp
Java String join() Method
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 ... The join() method joins one or more strings with a specified separator.
🌐
Vultr Docs
docs.vultr.com › java › standard library › java › lang › string › join()
Java String join() - Concatenate Strings | Vultr Docs
December 27, 2024 - The join() method in Java is a static method in the String class that concatenates any number of strings together with a specified delimiter. It is particularly useful when you need to build a single string out of multiple substrings, adding ...
🌐
Medium
medium.com › @idiotN › javas-string-join-method-explained-9126d8b360c7
Java’s String.join() Method Explained
September 8, 2024 - It inserts the delimiter between each element in the collection, array, or varargs, resulting in a single concatenated string. If no elements are provided, the method returns an empty string.
🌐
Medium
medium.com › javarevisited › nuanced-string-joining-in-java-7db547c331d0
Nuanced String Joining in Java | Javarevisited
April 23, 2024 - The String.join static method takes a CharSequence delimiter and either an array of CharSequence for the elements, or some kind of Iterable<CharSequence>. We can use the ArrayAdapter class from Eclipse Collections to convert the Integer array to an Iterable<CharSequence>.
Find elsewhere
🌐
Dot Net Perls
dotnetperls.com › join-java
Java - String.join Method - Dot Net Perls
January 25, 2024 - First, we call the String.join static method with an array of three Strings.
🌐
DEV Community
dev.to › satyam_gupta_0d1ff2152dcc › master-the-java-string-join-method-a-2025-guide-with-examples-best-practices-2oem
Master the Java String join() Method: A 2025 Guide with Examples & Best Practices - DEV Community
November 6, 2025 - Joining an Iterable (like a List or Set): String join(CharSequence delimiter, Iterable<? extends CharSequence> elements) Joining an Array of elements: String join(CharSequence delimiter, CharSequence...
🌐
Baeldung
baeldung.com › home › java › java string › array to string conversions
Array to String Conversions | Baeldung
September 16, 2026 - Additionally, we can use the Collectors.joining() method from the Java Streams API that joins strings from the Stream in the same order as its source array:
🌐
BeginnersBook
beginnersbook.com › 2017 › 10 › java-string-join-method
Java String join() method
June 4, 2024 - public class StringJoinExample { public static void main(String[] args) { // Here , is a delimiter and elements are strings String result = String.join(", ", "Cricket", "Hockey", "Tennis"); System.out.println(result); // Output: "Cricket, Hockey, Tennis" } } import java.util.Arrays; import java.util.List; public class StringJoinExample { public static void main(String[] args) { List<String> sports = Arrays.asList("Cricket", "Hockey", "Tennis"); // Here, we are joining elements of an ArrayList with // comma as delimiter String result = String.join(", ", sports); System.out.println(result); // Output: "Cricket", "Hockey", "Tennis" } } In the following example, we are using String.join() method with a variable number of string arguments.
🌐
Dba-presents
dba-presents.com › jvm › java › 268-java-join-string-array
Join string array in Java - performance
November 6, 2022 - A place where software development knowledge meets experience producing Java, Liquibase, database, and Agile articles. Here are tips, tricks, and online courses
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
🌐
Medium
medium.com › @cherukurisankar › stringjoiners-in-java-8-e1e97c195e32
Different ways to join the strings in Java | by Sivasankar Cherukuri | Medium
June 4, 2024 - List months = Arrays.asList("January", "February", "March", "April","May", "June", "July", "August", "September", "October", "November", "December"); String join = months.stream() .map(String::toUpperCase) .collect(Collectors.joining(", ")); System.out.println(join); Output: JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER · This concludes our discussion of StringJoiner and String in Java 8.
🌐
Medium
medium.com › @AlexanderObregon › javas-string-join-method-explained-77e1503095ec
Java’s String.join() Method Explained | Medium
September 2, 2024 - The String.join() method is particularly useful here because it eliminates the need for manual string concatenation or looping through array elements.
🌐
Programiz
programiz.com › java-programming › library › string › join
Java String join()
These strings are joined using the - delimiter. import java.util.ArrayList; class Main { public static void main(String[] args) { ArrayList<String> text = new ArrayList<>(); // adding elements to the arraylist text.add("Java"); text.add("is"); text.add("fun"); String result; result = ...
🌐
Baeldung
baeldung.com › home › java › java collections › join and split arrays and collections in java
Java - Join and Split Arrays and Collections | Baeldung
April 4, 2025 - In this quick tutorial, we’ll learn how to join and to split Arrays and Collections in Java, making good use of the new stream support. Let’s start by joining two Arrays together using Stream.concat: @Test public void whenJoiningTwoArrays_thenJoined() { String[] animals1 = new String[] { "Dog", "Cat" }; String[] animals2 = new String[] { "Bird", "Cow" }; String[] result = Stream.concat( Arrays.stream(animals1), Arrays.stream(animals2)).toArray(String[]::new); assertArrayEquals(result, new String[] { "Dog", "Cat", "Bird", "Cow" }); } Let’s do the same join with two Collections: @Test publ