Here you can find the source of join(Collection> strings, String separator)
public static String join(Collection<?> strings, String separator)
//package com.java2s; /******************************************************************************* * * Copyright (c) 2004-2011 Oracle Corporation. * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: /*from w w w. j a va2 s . c o m*/ * * Kohsuke Kawaguchi, Winston Prakash * * *******************************************************************************/ import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { /** * Concatenate multiple strings by inserting a separator. */ public static String join(Collection<?> strings, String separator) { StringBuilder buf = new StringBuilder(); boolean first = true; for (Object s : strings) { if (first) { first = false; } else { buf.append(separator); } buf.append(s); } return buf.toString(); } /** * Combines all the given collections into a single list. */ public static <T> List<T> join(Collection<? extends T>... items) { int size = 0; for (Collection<? extends T> item : items) { size += item.size(); } List<T> r = new ArrayList<T>(size); for (Collection<? extends T> item : items) { r.addAll(item); } return r; } }