Here you can find the source of join(Object[] parts, String delim)
Parameter | Description |
---|---|
parts | The string array to join. |
delim | The delimeter to join strings at. |
public static String join(Object[] parts, String delim)
//package com.java2s; /*//from w w w .ja va2s . com com.rivescript.RiveScript - The Official Java RiveScript Interpreter Copyright (C) 2010 Noah Petherbridge 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 2 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. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ import java.util.Collection; import java.util.Iterator; public class Main { /** * Join a string array into a single string. * * @param parts The string array to join. * @param delim The delimeter to join strings at. */ public static String join(Object[] parts, String delim) { StringBuilder buff = new StringBuilder(); for (int i = 0; i < parts.length; i++) { buff.append(parts[i].toString()); if (i < parts.length - 1) { buff.append(delim); } } return buff.toString(); } public static String join(Collection<String> collection, String delim) { StringBuilder buff = new StringBuilder(); for (Iterator<String> iter = collection.iterator(); iter.hasNext();) { String item = (String) iter.next(); buff.append(item); if (iter.hasNext()) { buff.append(delim); } } return buff.toString(); } }