Here you can find the source of join(java.util.Collection> strings, String delimiter)
public static String join(java.util.Collection<?> strings, String delimiter)
//package com.java2s; /******************************************************************************* * Copyright (C) 2006-2013 AITIA International, Inc. * // w w w . j a v a 2 s . co m * This program 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 3 of the License, or * (at your option) any later version. * * This program 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/>. ******************************************************************************/ public class Main { /** Returns a string representation of 'strings' which contains all elements * of 'strings' separated by 'delimiter'. */ public static String join(java.util.Collection<?> strings, String delimiter) { StringBuilder ans = new StringBuilder(); boolean first = true; for (Object s : strings) { if (first) first = false; else ans.append(delimiter); ans.append(s); } return ans.toString(); } /** Returns a string representation of 'args' which contains all elements * of 'args' separated by 'delimiter'. */ public static String join(String delimiter, Object... args) { if (args.length == 1) { if (args[0] instanceof Object[]) args = (Object[]) args[0]; else if (args[0] instanceof java.util.Collection) return join((java.util.Collection<?>) args[0], delimiter); } return join(java.util.Arrays.asList(args), delimiter); } /** Appends 'args' to 'sb'. * @return sb */ public static StringBuilder append(StringBuilder sb, Object... args) { if (sb == null) sb = new StringBuilder(); for (int i = 0; i < args.length; ++i) sb.append(args[i]); return sb; } }