In Java 8 or later:
String listString = String.join(", ", list);
In case the list is not of type String, a joining collector can be used:
String listString = list.stream().map(Object::toString)
.collect(Collectors.joining(", "));
Answer from Vitalii Fedorenko on Stack Overflow Top answer 1 of 16
1239
In Java 8 or later:
String listString = String.join(", ", list);
In case the list is not of type String, a joining collector can be used:
String listString = list.stream().map(Object::toString)
.collect(Collectors.joining(", "));
2 of 16
425
If you happen to be doing this on Android, there is a nice utility for this called TextUtils which has a .join(String delimiter, Iterable) method.
List<String> list = new ArrayList<String>();
list.add("Item 1");
list.add("Item 2");
String joined = TextUtils.join(", ", list);
Obviously not much use outside of Android, but figured I'd add it to this thread...
GeeksforGeeks
geeksforgeeks.org › java › join-two-arraylists-in-java
Join two ArrayLists in Java - GeeksforGeeks
November 16, 2024 - import java.util.*; public class GFG { public static void main(String args[]) { // Get the ArrayList1 ArrayList<String> list1 = new ArrayList<String>(); // Populate the ArrayList list1.add("Geeks"); list1.add("for"); list1.add("Geeks"); // Get the ArrayList2 ArrayList<String> list2 = new ArrayList<String>(); list2.add("GeeksForGeeks"); list2.add("A Computer Science Portal"); // Join the ArrayLists // using Collection.addAll() method list1.addAll(list2); // Print the joined ArrayList System.out.println(list1); } }
BeginnersBook
beginnersbook.com › 2013 › 12 › how-to-joincombine-two-arraylists-in-java
How to join/combine two ArrayLists in java
February 24, 2016 - In this example we are merging two ArrayLists in one single ArrayList and then displaying the elements of final List. package beginnersbook.com; import java.util.ArrayList; public class Details { public static void main(String [] args) { //First ArrayList ArrayList<String> arraylist1=new ArrayList<String>(); arraylist1.add("AL1: E1"); arraylist1.add("AL1: E2"); arraylist1.add("AL1: E3"); //Second ArrayList ArrayList<String> arraylist2=new ArrayList<String>(); arraylist2.add("AL2: E1"); arraylist2.add("AL2: E2"); arraylist2.add("AL2: E3"); //New ArrayList ArrayList<String> al= new ArrayList<String>(); al.addAll(arraylist1); al.addAll(arraylist2); //Displaying elements of the joined ArrayList for(String temp: al){ System.out.println(temp); } } }
CodeGym
codegym.cc › java blog › strings in java › java string join() method
Java String join() Method
January 8, 2025 - 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); } } Concatenating the array list elements with space as delimiter ·
Programiz
programiz.com › java-programming › examples › arraylist-string-conversion
Java Program to Convert the ArrayList into a string and vice versa | Programiz
March 14, 2024 - import java.util.ArrayList; class ...tln("ArrayList: " + languages); // convert the arraylist into a string String arraylist = String.join(", ", languages); System.out.println("String: " + arraylist); } }...
TutorialKart
tutorialkart.com › java › how-to-join-elements-of-arraylist-with-delimiter-in-java
How to Join Elements of ArrayList with Delimiter in Java?
December 24, 2020 - Call String.join() method and pass the delimiter string delimiter followed by the ArrayList<String> arrayList.
Dot Net Perls
dotnetperls.com › convert-arraylist-string-java
Java - Convert ArrayList to String - Dot Net Perls
For a simple string ArrayList, String.join is the best method to use.
TutorialsPoint
tutorialspoint.com › join-two-arraylists-in-java
How to merge two arrays in Java
August 1, 2023 - import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main { public static void main(String args[]) { String a[] = { "A", "E", "I" }; String b[] = { "O", "U" }; List list = new ArrayList(Arrays.asList(a)); list.addAll(Arrays.asList(b)); Object[] c = list.toArray(); System.out.println(Arrays.toString(c)); } } The above code sample will produce the following 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 the following example we first join within each nested Collection and then we join the result of each of them: @Test public void whenConvertNestedCollectionToString_thenConverted() { Collection<List<String>> nested = new ArrayList<>(); nested.add(Arrays.asList("Dog", "Cat")); nested.add(Arrays.asList("Cow", "Pig")); String result = nested.stream().map( nextList -> nextList.stream() .collect(Collectors.joining("-"))) .collect(Collectors.joining("; ")); assertEquals(result, "Dog-Cat; Cow-Pig"); }
GeeksforGeeks
geeksforgeeks.org › java › convert-arraylist-to-comma-separated-string-in-java
Convert ArrayList to Comma Separated String in Java - GeeksforGeeks
July 23, 2025 - We can convert ArrayList to a ... with a supplied prefix and ending with a supplied suffix. The join() method of the String class can be used to construct the same....
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 - package com.mkyong; import java.util.Arrays; import java.util.List; public class JavaStringExample1 { public static void main(String[] args) { List<String> list = Arrays.asList("a","b","c"); String result = String.join(",", list); System.out.println(result); } }
w3resource
w3resource.com › java-exercises › collection › java-collection-exercise-15.php
Java - Join two array lists
May 21, 2025 - Write a Java program to join two array lists. ... import java.util.ArrayList; import java.util.Collections; public class Exercise15 { public static void main(String[] args) { ArrayList<String> c1= new ArrayList<String>(); c1.add("Red"); c1.add("Green"); c1.add("Black"); c1.add("White"); c1.add("Pink"); System.out.println("List of first array: " + c1); ArrayList<String> c2= new ArrayList<String>(); c2.add("Red"); c2.add("Green"); c2.add("Black"); c2.add("Pink"); System.out.println("List of second array: " + c2); // Let join above two list ArrayList<String> a = new ArrayList<String>(); a.addAll(c1); a.addAll(c2); System.out.println("New array: " + a); } }
Mkyong
mkyong.com › home › java › java – how to join arrays
Java – How to join Arrays | mkyong.com
February 8, 2016 - this is a great post about how to join array thanks · Reply Helpful Report Spam or advertising Abusive or offensive Off topic · D · della pramukti raharjo · March 24, 2016 at 3:36 pm · import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class JoinArray { public static void main(String[] args) { String[] s1 = new String[] { “a”, “b”, “c” }; String[] s2 = new String[] { “d”, “e”, “f” }; List listString = new ArrayList(); for (String s : s1) listString.add(s); for (String s : s2) listString.add(s); String[] s3 = listString.toArray(new String[0]); System.out.println(“Value List String :” + listString.toString()); System.out.println(“Value join array :” + Arrays.toString(s3)); } } Reply Helpful Report Spam or advertising Abusive or offensive Off topic ·
Top answer 1 of 16
1155
In Java 8:
List<String> newList = Stream.concat(listOne.stream(), listTwo.stream())
.collect(Collectors.toList());
Java 16+:
List<String> newList = Stream.concat(listOne.stream(), listTwo.stream()).toList();
2 of 16
702
Off the top of my head, I can shorten it by one line:
List<String> newList = new ArrayList<String>(listOne);
newList.addAll(listTwo);
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
Another way of merging ArrayList is using Apache Commons Collection, Apart from several goodies, like creating a union of Set in Java, it provides a ListUtils class with a union method, which can be used to create a union of two List in Java. The result of the previous operation and is the same, It also preservers the order and appends elements of the second List after elements of the first List. Here is full code example of joining two List in Java.