In Java, String.join(delimiter, elements) is a static method that returns a new String made of all the elements with the delimiter placed between them, never at the start or the end.
It accepts either individual values (varargs or an array) or any Iterable, such as a List. It is the opposite of split and replaces the classic loop that has to avoid a trailing comma.
join() is a static method of java.lang.String, added in Java 8. Call it on the class name, as in String.join(...). No import is needed. Requires Java 8 or newer.
Syntax
Call it on the class name with a delimiter followed by the elements.
Elements can be any CharSequence: String, StringBuilder, and so on. To join numbers or other objects, convert them first, for example with a stream and Collectors.joining.
Library declarations
java
public static String join(CharSequence delimiter, CharSequence... elements);
public static String join(CharSequence delimiter, Iterable<? extends CharSequence> elements);
Parameters
Parameter
Description
delimiter
Text placed between neighboring elements.
elements
The values to join: varargs, an array, or an Iterable.
Return Value
Return Value
Description
String
The joined text; "" when there are no elements.
Java Examples
Example 1 — Join Values with Different Delimiters
Pass the values directly after the delimiter.
java
public class JoinVarargs {
public static void main(String[] args) {
String colors = String.join(", ", "red", "green", "blue");
String date = String.join("-", "2026", "11", "19");
System.out.println(colors);
System.out.println(date);
}
}
Output
red, green, blue
2026-11-19
How It Works
Between, not around.", " appears twice for three colors, with nothing before the first or after the last.
Any delimiter text. A single dash builds an ISO-style date from three parts.
Static call. No string object is needed to start; you write String.join on the class.