To join a array to string in Java you can use the following snippet.

Sample Java

public static String JoinArraylist(List<String> input, String delimiter, Boolean appendToEnd){
	Iterator<String> iteratorString = input.iterator();
	StringBuilder stringBuilder = new StringBuilder();
	for (;;) {
		stringBuilder.append(iteratorString.next());
		if (!iteratorString.hasNext()){ 
			break;
		}
		stringBuilder.append(delimiter);
	}
	if(appendToEnd){
		stringBuilder.append(delimiter);
	}
	return stringBuilder.toString();
}

One thought on “How to join a array to string in Java”

Leave a Reply