Here you can find the source of implode(String delim, Object[] objects)
Parameter | Description |
---|---|
delim | the delimiter |
objects | the objects to implode |
public static String implode(String delim, Object[] objects)
//package com.java2s; /**//from ww w . ja v a 2 s .com * This file is part of CubeEngine. * CubeEngine is licensed under the GNU General Public License Version 3. * * CubeEngine 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. * * CubeEngine 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 CubeEngine. If not, see <http://www.gnu.org/licenses/>. */ import java.util.Arrays; import java.util.Iterator; public class Main { /** * This method merges an array of objects to a single string * * @param delim the delimiter * @param objects the objects to implode * @return the imploded string */ public static String implode(String delim, Object[] objects) { return implode(delim, Arrays.asList(objects)); } /** * This method merges an array of objects to a single string * * @param delimiter the delimiter * @param objects the objects to implode * @return the imploded string */ public static String implode(String delimiter, Iterable objects) { Iterator<?> iterator = objects.iterator(); if (!iterator.hasNext()) { return ""; } StringBuilder sb = new StringBuilder(iterator.next().toString()); while (iterator.hasNext()) { sb.append(delimiter).append(iterator.next()); } return sb.toString(); } }