Here you can find the source of join(Collection
public static <T> String join(Collection<T> collections, String separator)
//package com.java2s; /******************************************************************************* * SQLPatcher - <a//from www . j a v a 2s .c o m * href="https://github.com/kbss/SQLPatcher">https://github.com/kbss * /SQLPatcher</a><br> * * Copyright (C) 2013 Serhii Krivtsov<br> * * SQLPatcher is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the License, or (at your option) any later * version.<br> * <br> * SQLPatcher is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR * A PARTICULAR PURPOSE. See the GNU General Public License for more details. * You should have received a copy of the GNU General Public License along with * this program. If not, see <http://www.gnu.org/licenses/>. <br> * * @author Serhii Krivtsov ******************************************************************************/ import java.util.Collection; public class Main { public static <T> String join(Collection<T> collections, String separator) { String result = ""; if (!collections.isEmpty()) { StringBuilder stringBuilder = new StringBuilder(); for (T object : collections) { stringBuilder.append(object.toString()).append(separator); } int resultLength = stringBuilder.length(); stringBuilder.delete(resultLength - separator.length(), resultLength); result = stringBuilder.toString(); } return result; } public static <T> String join(Collection<T> collection) { return join(collection, ", "); } }