Here you can find the source of implode(Collection
public static String implode(Collection<String> items, String join)
//package com.java2s; /*//from ww w . j a v a 2 s .c o m * Copyright 2013 Nebojsa Cvetkovic. All rights reserved. * * This file is part of JunglistIRC. * * JunglistIRC 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. * * JunglistIRC 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 JunglistIRC. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Collection; public class Main { public static String implode(Collection<String> items, String join) { String result = ""; int i = 0; for (String s : items) { result += s; if (i < items.size() - 1) { result += join; } i++; } return result; } public static String implode(String[] items, String join) { return implode(items, join, 0, items.length); } public static String implode(String[] items, String join, int begin, int end) { String result = ""; for (int i = begin; i < end; i++) { result += items[i]; if (i < end - 1) { result += join; } } return result; } }