Here you can find the source of implode(Object[] elements, String delimiter)
Parameter | Description |
---|---|
elements | the array to combine to a single string. |
delimiter | the delimiter to put between the combined elements. |
public static String implode(Object[] elements, String delimiter)
//package com.java2s; /**//w ww. j a v a 2s. co m * NetP5 is a processing and java library for tcp and udp ip communication. * * 2006 by Andreas Schlegel * * This library 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 2.1 * of the License, or (at your option) any later version. * This library 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 this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * * @author Andreas Schlegel (http://www.sojamo.de) * */ public class Main { /** * Combines an array to a string, using the specified delimiter. * * @param elements * the array to combine to a single string. * @param delimiter * the delimiter to put between the combined elements. * @return the array combined to a string. */ public static String implode(Object[] elements, String delimiter) { StringBuffer buffer = new StringBuffer(""); for (int i = 0; i < elements.length - 1; i++) { buffer.append((String) elements[i] + delimiter); } buffer.append((String) elements[elements.length - 1]); return buffer.toString(); } /** * Combines an array to a string, using a comma and a space as delimiter. * * @param elements * the array to combine to a single string. * @return the array combined to a string. */ public static String implode(Object[] elements) { return implode(elements, ", "); } }