Here you can find the source of join(ArrayList
public static String join(ArrayList<String> s, String delimiter)
//package com.java2s; /*//from w w w .j a v a 2 s. c o 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: * http://www.gnu.org/licenses/gpl.txt */ import java.util.ArrayList; public class Main { public static String join(String[] s, String delimiter) { StringBuilder buffer = new StringBuilder(); for (int i = 0; i < s.length; i++) { if (i != 0) buffer.append(delimiter); buffer.append(s[i]); } return buffer.toString(); } public static String join(ArrayList<String> s, String delimiter) { StringBuilder buffer = new StringBuilder(); for (int i = 0; i < s.size(); i++) { if (i != 0) buffer.append(delimiter); buffer.append(s.get(i)); } return buffer.toString(); } public static String join(ArrayList<String> s, String delimiter, ArrayList<Integer> indices) { StringBuilder buffer = new StringBuilder(); for (int i = 0; i < s.size(); i++) { if (i != 0) buffer.append(delimiter); buffer.append(s.get(indices.get(i))); } return buffer.toString(); } }