Here you can find the source of join(List
public static String join(List<String> list)
//package com.java2s; //License from project: Open Source License import java.util.List; public class Main { public static String join(List<String> list) { return join(list, null); }// ww w .j a v a 2s . c o m public static String join(List<String> list, char separator) { return join(list, String.valueOf(separator)); } public static String join(List<String> list, String separator) { if (list == null) { return null; } if (list.isEmpty()) { return ""; } int seplen; if (separator == null) { seplen = 0; } else { seplen = separator.length(); } int len = -seplen; for (String s : list) { len += seplen; if (s != null) { len += s.length(); } } StringBuffer buf = new StringBuffer(len); boolean first = true; for (String s : list) { if (first) { first = false; } else { if (seplen != 0) { buf.append(separator); } } if (s != null) { buf.append(s); } } return buf.toString(); } }