Here you can find the source of join(String delimiter, Collection> objects)
public static String join(String delimiter, Collection<?> objects)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; public class Main { public static String join(String delimiter, Object... objects) { return join(delimiter, Arrays.asList(objects)); }//from w ww .j a va 2 s . c o m public static String join(String delimiter, Collection<?> objects) { StringBuilder sb = new StringBuilder(); Iterator<?> iterator = filterNulls(objects).iterator(); while (iterator.hasNext()) { Object next = iterator.next(); sb.append(String.valueOf(next)); if (iterator.hasNext()) { sb.append(delimiter); } } return sb.toString(); } public static List<?> filterNulls(Collection<?> objects) { List<Object> notNulls = new ArrayList<>(); for (Object o : objects) { if (o != null) { notNulls.add(o); } } return notNulls; } }