Here you can find the source of join(final ArrayList
public static String join(final ArrayList<String> array, final String separator)
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Iterator; public class Main { public static String join(final ArrayList<String> array, final String separator) { StringBuffer result = new StringBuffer(); if (array != null && array.size() > 0) { for (String str : array) { result.append(str);//from w ww . jav a 2s. co m result.append(separator); } result.delete(result.length() - 1, result.length()); } return result.toString(); } public static String join(final Iterator<String> iter, final String separator) { StringBuffer result = new StringBuffer(); if (iter != null) { while (iter.hasNext()) { String key = iter.next(); result.append(key); result.append(separator); } if (result.length() > 0) result.delete(result.length() - 1, result.length()); } return result.toString(); } }