Java 8 – Join String Array – Convert Array to String

Java examples to join string array to produce single String. This code can be used to convert array to string in Java. We may need this information many times during development specially while parsing contents out of JSON or XML.

1. Join String Array – Java 8 String.join()

String.join() method has two overloaded forms.

Join multiple string arguments

This method takes all strings in var-args format and all strings are passed as argument in the method. The return string is received by appending all strings delimited by argument separator.

String join(CharSequence delimiter, CharSequence... elements)

This method can be used to join multiple strings which are not yet in form of collection or array.

String joinedString = String.join(", ", "How", "To", "Do", "In", "Java");


How, To, Do, In, Java

Join array or list of strings

String join(CharSequence delimiter, Iterable<? extends CharSequence> elements)

This method is used to join array of strings or list of strings.

Java program to join list of strings

List<String> strList = Arrays.asList("How", "To", "Do", "In", "Java");
String joinedString = String.join(", ", strList);



How, To, Do, In, Java

Java program to join array of strings

String[] strArray = { "How", "To", "Do", "In", "Java" };
String joinedString = String.join(", ", strArray);



How, To, Do, In, Java

2. Java 8 StringJoiner for formatted output

Using StringJoiner class, we can produce formatted output of joined string. This is specially useful while using lambda collectors.

2.1. Method Syntax

It’s constructor takes three arguments – delimiter [mandatory], and optionally prefix and suffix.

StringJoiner(CharSequence delimiter)
StringJoiner(CharSequence delimiter, CharSequence prefix, CharSequence suffix)

2.2. StringJoiner Example

Run the example with similar input as above example to join multiple strings. We want to format the output as [How, To, Do, In, Java], then we can use below code:

StringJoiner joiner = new StringJoiner(", ", "[", "]");



[How, To, Do, In, Java]

3. String list of string with Collectors.joining()

While using Java 8 lambda, we can use Collectors.joining() to convert list to String.

List<String> numbers = Arrays.asList("How", "To", "Do", "In", "Java");

String joinedString = 	numbers
						.collect(Collectors.joining(", ","[","]"));



[How, To, Do, In, Java]

4. Join String Array using StringUtils.join()

The StringUtils class of the Commons Langs library has several join() methods that can be used to combine an array or list of strings into a single string.

4.1. Maven Dependency


4.2. StringUtils.join() Example

See given examples. First we are joining string array with empty string. In second example, we are joining array with comma.

String[] strArray = { "How", "To", "Do", "In", "Java" };

String joinedString = StringUtils.join(strArray);

String joinedString2 = StringUtils.join(strArray, ", ");


How, To, Do, In, Java

Use above given examples to concatenate string array with in Java.

Happy Learning !!


Java 8 String Doc
StringJoiner Java Doc
Apache Commons StringUtils Doc

Was this post helpful?

Join 7000+ Awesome Developers

Get the latest updates from industry, awesome resources, blog updates and much more.

* We do not spam !!

2 thoughts on “Java 8 – Join String Array – Convert Array to String”

  1. Hello! I saw in the example 2 the following:

    String joinedString = numbers
    .map(i -> i.toString())…..

    In this case I think that the map(..) is unnecessary because the collection is already a string.


Leave a Comment


A blog about Java and related technologies, the best practices, algorithms, and interview questions.