String.join

With Java 8 you can do this without any third party library.

If you want to join a Collection of Strings you can use the String.join() method:

List<String> list = Arrays.asList("foo", "bar", "baz");
String joined = String.join(" and ", list); // "foo and bar and baz"

Collectors.joining

If you have a Collection with another type than String you can use the Stream API with the joining Collector:

List<Person> list = Arrays.asList(
  new Person("John", "Smith"),
  new Person("Anna", "Martinez"),
  new Person("Paul", "Watson ")
);

String joinedFirstNames = list.stream()
  .map(Person::getFirstName)
  .collect(Collectors.joining(", ")); // "John, Anna, Paul"

The StringJoiner class may also be useful.

Answer from micha on Stack Overflow
🌐
Baeldung
baeldung.com › home › java › java list › joining a list in java with commas and “and”
Joining a List in Java With Commas and “and” | Baeldung
March 7, 2025 - Then, if the list contains three or more strings, we take “, “ as the separator to join the elements in a sublist of the input, which excludes the last string.
People also ask

How do I repeat a string in Java?
On Java 11+, call "ab".repeat(3), which returns ababab. A count of 0 returns an empty string and a negative count throws IllegalArgumentException: count is negative: -1. On Java 8, String.join("", Collections.nCopies(3, "ab")) gives the same ababab, and swapping the empty string for ", " repeats with a separator. Guava’s Strings.repeat and Commons’ StringUtils.repeat are the library versions.
🌐
compilebytes.com
compilebytes.com › home › examples › java examples › how to join a list into a string in java
How to Join a List Into a String in Java | CompileBytes
What is the difference between String.join, Collectors.joining and StringJoiner?
They produce the same result and differ in where the elements come from. String.join takes strings you already have in a collection or array. Collectors.joining is the last step of a stream, so it pairs with map, filter and sorted, and it can add a prefix and suffix. StringJoiner lets you add() one element at a time and set a custom value for the empty case with setEmptyValue.
🌐
compilebytes.com
compilebytes.com › home › examples › java examples › how to join a list into a string in java
How to Join a List Into a String in Java | CompileBytes
Why does String.join not compile with a List?
String.join only accepts an Iterable or CharSequence varargs, and Integer is neither, so javac reports no suitable method found for join(java.lang.String,java.util.List). Convert the elements in a stream: nums.stream().map(String::valueOf).collect(Collectors.joining(", ")) turns List.of(3, 1, 4, 1, 5) into 3, 1, 4, 1, 5.
🌐
compilebytes.com
compilebytes.com › home › examples › java examples › how to join a list into a string in java
How to Join a List Into a String in Java | CompileBytes
🌐
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); } }
🌐
Mkyong
mkyong.com › home › java › java – how to join list string with commas
Java – How to join List String with commas | mkyong.com
November 29, 2018 - In Java, we can use String.join(",", list) to join a List String with commas.
🌐
Vultr Docs
docs.vultr.com › java › standard library › java › lang › string › join()
Java String join() - Concatenate Strings | Vultr Docs
December 27, 2024 - Whether you're working with lists, arrays, or any collection of string elements, the join() method offers a straightforward approach to generate a single, unified string. Employing this method in practical scenarios, such as data formatting or creating compound messages, can greatly enhance the efficiency and readability of your Java programs.
🌐
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" } }
🌐
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 - Okay, cool, it joins strings. But where does this fit in a real project? Everywhere! Building CSV Data Need to generate a CSV line from a list of data? join() is your best friend. java List userData = List.of("John Doe", "john.doe@email.com", "New York"); String csvLine = String.join(",", userData); // Output: John Doe,john.doe@email.com,New York
Find elsewhere
🌐
Baeldung
baeldung.com › home › java › java string › converting a list to string in java
Converting a List to String in Java | Baeldung
July 30, 2026 - If our elements in the List aren’t subclasses of CharSequence, we can first convert the List to a List<String>, and then pass it to String.join():
🌐
CompileBytes
compilebytes.com › home › examples › java examples › how to join a list into a string in java
How to Join a List Into a String in Java | CompileBytes
September 25, 2026 - If the list holds numbers or other objects, stream it and convert each element first: list.stream().map(String::valueOf).collect(Collectors.joining(", ")). Before Java 8 the JDK had no join method at all, which is why old answers loop over a StringBuilder or pull in Guava's Joiner or Apache Commons' StringUtils.join.
🌐
Medium
medium.com › javarevisited › nuanced-string-joining-in-java-7db547c331d0
Nuanced String Joining in Java | Javarevisited
April 23, 2024 - I wrote an article for 97 Things Every Java Programmer Should Know with the title “Learn to Kata and Kata to Learn.” In this article, I iterate through some example Java code using Collectors.joining() and String.join() to create a comma separated list of names.
🌐
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. The same method accepts a List or any other Iterable of strings.
🌐
Blogger
javarevisited.blogspot.com › 2016 › 06 › 10-examples-of-joining-string-in-java-8.html
10 Examples of Joining String in Java - String.join vs StringJoiner
May 11, 2023 - Still, you won't find any such ... String by a delimiter. A join() method is added into the String class to convert an array of String or a list of String joined by a delimiter of your choice....
🌐
Sabe
sabe.io › blog › java-join-list-strings-delimiter
How to Join a List of Strings with a Delimiter in Java - Sabe.io
November 26, 2022 - In Java, lists are common because they allow you to store several pieces of the same type of data inside a single variable. For example, you can store a list of string, a list of numbers, or a list of objects. When you have a list of strings, you'll sometimes want to join them together into a single string.
🌐
amitph
amitph.com › home › java › convert list to concatenated string with delimiter in java
List of Strings to Concatenated String with Delimiter in Java | amitph
November 22, 2024 - We will see different examples to join the String. ... Firstly, concatenate a string without any delimiter. List<String> words = Arrays.asList("Convert", "List", "of", "Strings", "To", "String"); String concatenatedString = ""; for(String word: ...
🌐
Java67
java67.com › 2016 › 08 › java-8-stringjoin-example.html
How to Join Multiple Strings in Java 8 - String join() Example | Java67
You can use the String.join() method to join a number of String literals, String objects, String elements from an array, or String elements from List, Set, or any collection because it accepts an Iterable.
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › java › stringjoiner-class-vs-string-join-method-to-join-string-in-java-with-examples
StringJoiner Class vs String.join() Method to Join String in Java with Examples - GeeksforGeeks
July 23, 2025 - The join() method was introduced in java string since JDK 1.8. String.join() method takes two parameters first is a delimiter and the second can be a list or array of elements or elements separated by ,(comma).
🌐
Baeldung
baeldung.com › home › java › java string › java stringjoiner
Java StringJoiner | Baeldung
August 30, 2024 - ... @Test public void ... "[Red,Green,Blue]"); } If we want to join all elements of a list, we’ll have to loop through the list....