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 - >> Learn Java Basics · When working with a string collection, concatenating these strings with specific separators is a common task. Fortunately, various solutions are at our disposal, including using String.join() and Collectors.joining(). In this quick tutorial, we’ll explore an interesting string concatenation problem: joining strings in a more natural language-like manner. Let’s understand the problem with an example. Let’s say we have a list of strings {“A”, “B”, “C”, “D”}. If we want to join them with commas as the separator, the result would be “A, B, C, D“. So far, so good.
🌐
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.
🌐
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); } }
🌐
javaspring
javaspring.net › blog › java-join-list
Java Join List: A Comprehensive Guide — javaspring.net
The String.join() method takes a delimiter as the first argument and an Iterable (such as a List) as the second argument. It returns a string where the elements of the Iterable are joined together with the specified delimiter.
🌐
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 - The most straightforward way to join a list of strings together is to use the String.join() method. This method is called on the String class and takes two arguments: ... JAVAList<String> strings = Arrays.asList("one", "two", "three"); String ...
🌐
Programiz
programiz.com › java-programming › examples › join-two-lists
Java Program to Join Two Lists
import java.util.ArrayList; import java.util.List; public class JoinLists { public static void main(String[] args) { List<String> list1 = new ArrayList<String>(); list1.add("a"); List<String> list2 = new ArrayList<String>(); list2.add("b"); List<String> joined = new ArrayList<String>(); joined.addAll(list1); joined.addAll(list2); System.out.println("list1: " + list1); System.out.println("list2: " + list2); System.out.println("joined: " + joined); } }
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 - Example 1: The Classic Comma-Separated List This is the most common use case, and it's where join() shines. java import java.util.Arrays; import java.util.List; public class JoinDemo { public static void main(String[] args) { List<String> languages = Arrays.asList("Java", "Python", "JavaScript", "Golang"); // The old, clunky way (we've all been there) // ...
🌐
Techie Delight
techiedelight.com › home › java › join two lists in java
Join two lists in Java | Techie Delight
July 7, 2026 - The Java Stream provides concat() that takes two streams as input and creates a lazily concatenated stream whose elements are all the elements of the first stream, followed by all the elements of the second stream. ... This is a slight variation of the List.addAll() approach discussed earlier by using streams in Java 8 and above:
🌐
Vultr Docs
docs.vultr.com › java › examples › join two lists
Java Program to Join Two Lists | Vultr Docs
December 16, 2024 - Ensure you have two lists to combine. Use Stream.concat() from Java 8 to merge the streams of both lists, then collect results into a new list.
🌐
David Vlijmincx
davidvlijmincx.com › home › java › java stream join lists
How to Join or Concatenate Two Lists in Java Using Streams | David Vlijmincx
March 10, 2022 - The easiest way to join two lists with Streams is by using the Stream.concat(Stream a, Stream b) method. The method takes two Stream instances as parameters and puts the second Stream behind the first Stream.
🌐
DigitalOcean
digitalocean.com › community › tutorials › merge-two-lists-in-java
How to Merge Two Lists in Java? | DigitalOcean
August 3, 2022 - Technical tutorials, Q&A, events — This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
🌐
Baeldung
baeldung.com › home › java › java collections › java – combine multiple collections
Java - Combine Multiple Collections | Baeldung
May 11, 2024 - Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time. ... In this tutorial, we will illustrate how to concatenate multiple collections into one logical collection. We’ll be exploring five different approaches – two using Java 8, one using Guava, one using Apache Commons Collections, and one using only the standard Java 7 SDK.
🌐
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 ... through some example Java code using Collectors.joining() and String.join() to create a comma separated list of names....
🌐
Blogger
javarevisited.blogspot.com › 2013 › 08 › -example-to-merge-or-join-multiple-List-in-Java.html
2 Example to Merge or Join Multiple List in Java - Tutorial
There are two main ways to merge, join or combine two List in Java, by using addAll(Collection c) method or by using ListUtils union method from Apache commons Collection. In this Java tutorial, we will see examples of both approaches.
🌐
BeginnersBook
beginnersbook.com › 2017 › 10 › java-string-join-method
Java String join() method
June 4, 2024 - public class StringJoinExample ... 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....
🌐
Mkyong
mkyong.com › home › java › how to join two lists in java
How to join two Lists in Java | mkyong.com
October 7, 2013 - package com.mkyong.example; import java.util.ArrayList; import java.util.List; public class JoinListsExample { public static void main(String[] args) { List<String> listA = new ArrayList<String>(); listA.add("A"); List<String> listB = new ArrayList<String>(); listB.add("B"); List<String> listFinal = new ArrayList<String>(); listFinal.addAll(listA); listFinal.addAll(listB); //same result //List<String> listFinal = new ArrayList<String>(listA); //listFinal.addAll(listB); System.out.println("listA : " + listA); System.out.println("listB : " + listB); System.out.println("listFinal : " + listFinal); } }