Here you can find the source of implode(Object[] array, String separator)
public static String implode(Object[] array, String separator)
//package com.java2s; /*************************************************************************** * Copyright (c) 2006 Eike Stepper, Fuggerstr. 39, 10777 Berlin, Germany. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * //from ww w . jav a 2s .com * Contributors: * Eike Stepper - initial API and implementation **************************************************************************/ import java.util.Collection; import java.util.Iterator; public class Main { public static String implode(Collection collection, String separator) { if (collection == null) return null; if (collection.size() == 0) return ""; Iterator iter = collection.iterator(); StringBuffer result = new StringBuffer(iter.next().toString()); while (iter.hasNext()) { if (separator != null) result.append(separator); result.append(iter.next().toString()); } return result.toString(); } public static String implode(Object[] array, String separator) { if (array == null) return null; if (array.length == 0) return ""; StringBuffer result = new StringBuffer(array[0].toString()); for (int i = 1; i < array.length; i++) { if (separator != null) result.append(separator); result.append(array[i].toString()); } return result.toString(); } }