Here you can find the source of join(Collection> c, String delim)
Parameter | Description |
---|---|
c | An iterable collection of Objects |
delim | a string to put between each object |
public static String join(Collection<?> c, String delim)
//package com.java2s; /*/*from w w w. jav a2 s .com*/ * TextUtilities.java - Various text functions * Copyright (C) 1998, 2005 Slava Pestov * :tabSize=4:indentSize=4:noTabs=false: * :folding=explicit:collapseFolds=1: * * 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 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ import java.util.*; public class Main { /** Similar to perl's join() method on lists, * but works with all collections. * * @param c An iterable collection of Objects * @param delim a string to put between each object * @return a joined toString() representation of the collection * * @since jedit 4.3pre3 */ public static String join(Collection<?> c, String delim) { StringBuilder retval = new StringBuilder(); Iterator<?> itr = c.iterator(); if (itr.hasNext()) retval.append(itr.next()); else return ""; while (itr.hasNext()) { retval.append(delim); retval.append(itr.next()); } return retval.toString(); } }