Java – Join Elements of String Array with Delimiter

To join elements of given string array strArray with a delimiter string delimiter, use String.join() method. Call String.join() method and pass the delimiter string delimiter followed by the string array strArray.

String.join() returns a single string with all the string elements of Array joined with delimiter in between them.

Java Program

</>
Copy
public class Example {
	public static void main(String[] args) {
		String delimiter = "--";
		String strArray[] = {"hello", "world", "welcome"};
		String result = String.join(delimiter, strArray);
		System.out.println("Resulting String:   " + result);
	}
}

Output

Resulting String:   hello--world--welcome

Conclusion

In this Java Tutorial, we learned how to join elements of string array with a specified delimiter in Java.