Here you can find the source of join(Collection extends Object> elements, String separator)
public static String join(Collection<? extends Object> elements, String separator)
//package com.java2s; //License from project: Creative Commons License import java.util.Collection; import java.util.Iterator; public class Main { public static String join(Collection<? extends Object> elements, String separator) { Iterator<? extends Object> iterator = elements.iterator(); if (iterator.hasNext()) { StringBuilder builder = new StringBuilder(); builder.append(iterator.next().toString()); while (iterator.hasNext()) { builder.append(separator); builder.append(iterator.next().toString()); }// www. j a v a 2s. c o m return builder.toString(); } else { return ""; } } public static String join(Collection<? extends Object> elements) { return join(elements, ""); } }