Here you can find the source of join(String separator, Collection> list)
public static String join(String separator, Collection<?> list)
//package com.java2s; //License from project: Apache License import java.util.Collection; import java.util.Iterator; public class Main { public static String join(String separator, Collection<?> list) { return join(separator, null, null, list); }//from w w w. ja v a2 s. co m public static String join(String separator, Collection<?> list, boolean quoted) { return join(separator, null, null, list, quoted); } public static String join(String separator, String prefix, String suffix, Collection<?> list, boolean quoted) { StringBuilder sb = new StringBuilder(); if (null != prefix) sb.append(prefix).append(separator); Iterator<?> itr = list.iterator(); if (itr.hasNext()) { if (quoted) sb.append("\""); sb.append(itr.next()); if (quoted) sb.append("\""); } while (itr.hasNext()) { sb.append(separator); if (quoted) sb.append("\""); sb.append(itr.next()); if (quoted) sb.append("\""); } if (null != suffix) sb.append(separator).append(suffix); return sb.toString(); } public static String join(String separator, String prefix, String suffix, Collection<?> list) { return join(separator, prefix, suffix, list, false); } public static String join(String separator, String... list) { StringBuilder sb = new StringBuilder(); if (list.length > 0) { sb.append(list[0]); for (int i = 1; i < list.length; ++i) sb.append(separator).append(list[i]); } return sb.toString(); } }