Here you can find the source of stringsToCommaString(List strings)
Parameter | Description |
---|---|
strings | The list of strings. |
public static String stringsToCommaString(List strings)
//package com.java2s; /* $Id: Utils.java 187 2010-01-13 17:41:03Z linus $ ***************************************************************************** * Copyright (c) 2009 Contributors - see below * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://from w w w .java 2 s . c om * drahmann ***************************************************************************** * * Some portions of this file was previously release using the BSD License: */ import java.util.Iterator; import java.util.List; public class Main { /** * Takes a list of strings and joins them with a comma. * * @param strings * The list of strings. * @return The joined string. */ public static String stringsToCommaString(List strings) { return stringsToString(strings, ","); } /** * Takes a list of strings and joins them with <code>separators</code>. * * @param strings * The list of strings to be joined. * @param separators * The string that should be put between the separate strings. * @return The joined string. */ public static String stringsToString(List strings, String separators) { StringBuffer sb = new StringBuffer(); Iterator it = strings.iterator(); while (it.hasNext()) { String s = (String) it.next(); if (sb.length() > 0) { sb.append(separators); } sb.append(s); } return sb.toString(); } }