Here you can find the source of join(List
public static String join(List<String> list, String separator)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class Main { public static String join(List<String> list, String separator) { if (list == null) { return null; }/*w ww. j a va 2s . co m*/ if (list.isEmpty()) { return ""; } if (separator == null) { // ??? separator = ""; } StringBuilder sb = new StringBuilder(); Iterator<String> it = list.iterator(); while (it.hasNext()) { sb.append(it.next()); if (it.hasNext()) { sb.append(separator); } } return sb.toString(); } public static String join(String s1, String s2, String separator) { List<String> list = new ArrayList<String>(); list.add(s1); list.add(s2); return join(list, separator); } public static String join(String s1, String s2, String s3, String separator) { List<String> list = new ArrayList<String>(); list.add(s1); list.add(s2); list.add(s3); return join(list, separator); } }