Here you can find the source of join(final Collection
public static String join(final Collection<String> collection, final String separator)
//package com.java2s; /*/*from w w w.j ava 2 s . c om*/ * * SchemaCrawler * http://sourceforge.net/projects/schemacrawler * Copyright (c) 2000-2015, Sualeh Fatehi. * * This library is free software; you can redistribute it and/or modify it under the terms * of the GNU Lesser General Public License as published by the Free Software Foundation; * either version 2.1 of the License, or (at your option) any later version. * * This library 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 Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License along with this * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307, USA. * */ import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.Map; import java.util.Map.Entry; import java.util.Set; public class Main { public static String join(final Collection<String> collection, final String separator) { if (collection == null || collection.isEmpty()) { return null; } final StringBuilder buffer = new StringBuilder(); for (final Iterator<String> iterator = collection.iterator(); iterator.hasNext();) { buffer.append(iterator.next()); if (iterator.hasNext()) { buffer.append(separator); } } return buffer.toString(); } public static String join(final Map<String, String> map, final String separator) { if (map == null || map.isEmpty()) { return null; } final StringBuilder buffer = new StringBuilder(); final Set<Entry<String, String>> entrySet = map.entrySet(); for (final Iterator<Entry<String, String>> iterator = entrySet.iterator(); iterator.hasNext();) { final Entry<String, String> entry = iterator.next(); buffer.append(entry.getKey()).append("=").append(entry.getValue()); if (iterator.hasNext()) { buffer.append(separator); } } return buffer.toString(); } public static String join(final String[] collection, final String separator) { return join(Arrays.asList(collection), separator); } }