Here you can find the source of join(Collection> col, String separator)
public static String join(Collection<?> col, String separator)
//package com.java2s; import java.util.Collection; import java.util.Iterator; public class Main { public static String join(Object[] arr, String separator) { StringBuilder sb = new StringBuilder(); if (arr.length > 0) { sb.append(arr[0].toString()); }//from w ww. jav a2 s . com for (int i = 1; i < arr.length; i++) { sb.append(separator); sb.append(arr[i]); } return sb.toString(); } public static String join(Collection<?> col, String separator) { StringBuilder sb = new StringBuilder(); Iterator<?> it = col.iterator(); if (!col.isEmpty()) { Object obj = it.next(); sb.append(obj.toString()); } while (it.hasNext()) { Object obj = it.next(); sb.append(separator); sb.append(obj.toString()); } return sb.toString(); } public static String join(Object[] arr) { return join(arr, ","); } public static String join(Collection<?> arr) { return join(arr, ","); } public static boolean isEmpty(String s) { return s == null || s.isEmpty(); } }