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 - Now, letโ€™s walk through the code quickly. First, we handle cases where the list contains less than three elements using String.join(โ€ and โ€œ, list).
๐ŸŒ
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); } }
๐ŸŒ
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.
๐ŸŒ
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" } }
๐ŸŒ
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 ...
๐ŸŒ
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():
Find elsewhere
๐ŸŒ
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
๐ŸŒ
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.
๐ŸŒ
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: ...
๐ŸŒ
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.
๐ŸŒ
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 - This is used to join any number of arbitrary String as it accepts individual String as a variable argument, so you can pass as many String as you want. The second version of join() accepts a CharSequence delimiter and Iterable of CharSequence, which means you can use this to join a list of String or an array of String in Java.
๐ŸŒ
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-string-join-examples
Java String join() with examples - GeeksforGeeks
April 8, 2025 - join() method is included in java string since JDK 1.8. There are two types of join() methods in java string.
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
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).