Here you can find the source of concat(Collection
public static final String concat(Collection<String> pieces, String delim)
//package com.java2s; /*//from www . ja va 2 s . c o m Copyright 2009 Semantic Discovery, Inc. (www.semanticdiscovery.com) This file is part of the Semantic Discovery Toolkit. The Semantic Discovery Toolkit 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 3 of the License, or (at your option) any later version. The Semantic Discovery Toolkit 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 The Semantic Discovery Toolkit. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Collection; import java.util.Iterator; public class Main { /** * Build a string concatenating the pieces from startIndex (inclusive) to endIndex * (exclusive), adding the delim between each. */ public static final String concat(String[] pieces, String delim, int startIndex, int endIndex) { final StringBuilder result = new StringBuilder(); for (int i = startIndex; i < endIndex; ++i) { if (result.length() > 0) result.append(delim); result.append(pieces[i]); } return result.toString(); } /** * Build a string concatenating the pieces, adding the delim between each. */ public static final String concat(Collection<String> pieces, String delim) { return concat(pieces, delim, 0, pieces.size()); } /** * Build a string concatenating the pieces from startIndex (inclusive) to endIndex * (exclusive), adding the delim between each. */ public static final String concat(Collection<String> pieces, String delim, int startIndex, int endIndex) { final StringBuilder result = new StringBuilder(); int index = 0; for (Iterator<String> iter = pieces.iterator(); iter.hasNext();) { final String piece = iter.next(); if (index >= endIndex) break; if (index < startIndex) continue; if (result.length() > 0) result.append(delim); result.append(piece); } return result.toString(); } }