Here you can find the source of joinStrings(String delim, Collection
static public String joinStrings(String delim, Collection<String> strs)
//package com.java2s; //License from project: Open Source License import java.util.Collection; public class Main { /**/* w ww . jav a 2 s. c o m*/ * Joins a list of strings together sepeated by a delim in the middle */ static public String joinStrings(String delim, String... strs) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < strs.length - 1; i++) { sb.append(strs[i]); sb.append(delim); } sb.append(strs[strs.length - 1]); return sb.toString(); } /** * Joins a collection of strings together sepeated by a delim in the middle */ static public String joinStrings(String delim, Collection<String> strs) { StringBuilder sb = new StringBuilder(); boolean first = true; for (String str : strs) { if (first) { first = false; } else { sb.append(delim); } sb.append(str); } return sb.toString(); } }