by Sai gowtham

How to join an array of strings into a string in Java

To join an array of strings into a single string we can use the join() method in Java.

In this below example, we are joining each string in an array without any delimiter.

String[] array = new String[] { "how", "are", "you" };

String joined = String.join("", array);

System.out.println(joined);

Output:

howareyou

If you want a string which is separated by the delimiter like comma , you need to specify in the join() method.

String[] array = new String[] { "how", "are", "you" };

String joined = String.join(",", array);

System.out.println(joined);
how,are,you

Top Udemy Courses

JavaScript - The Complete Guide 2020 (Beginner + Advanced)
JavaScript - The Complete Guide 2020 (Beginner + Advanced)
45,614 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
130,921 students enrolled
48.5 hours of video content
View Course