Here you can find the source of join(List elements, String sep)
Parameter | Description |
---|---|
elements | the strings to join together |
sep | the separator string |
public static String join(List elements, String sep)
//package com.java2s; /*/*w ww.jav a2s . c o m*/ * Copyright (C) 2001-2004 Red Hat, Inc. All Rights Reserved. * * 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 */ import java.util.List; import java.util.Iterator; public class Main { /** * "join" a List of Strings into a single string, with each string * separated by a defined separator string. * @deprecated use {@link com.arsdigita.util.StringUtils} * * @param elements the strings to join together * @param sep the separator string * @return the strings joined together */ public static String join(List elements, String sep) { StringBuffer sb = new StringBuffer(); boolean first = true; Iterator iter = elements.iterator(); while (iter.hasNext()) { String element = (String) iter.next(); if (!first) { sb.append(sep); } else { first = false; } sb.append(element); } return sb.toString(); } }