Java Comma Separated List stringsToCommaString(List strings)

Here you can find the source of stringsToCommaString(List strings)

Description

Takes a list of strings and joins them with a comma.

License

Open Source License

Parameter

Parameter Description
strings The list of strings.

Return

The joined string.

Declaration

public static String stringsToCommaString(List strings) 

Method Source Code

//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();
    }
}

Related

  1. splitCommandsToList(String row, String delimiter)
  2. splitListByComma(List hosts)
  3. splitListWithComma(List StringList)
  4. splitOnCommas(final String commaSeparatedList)
  5. stringListStringWithoutBracketsCommaSeparated(List list)
  6. stringToCommaText(List strings)
  7. stringToList(final String commaSeparated)
  8. stringToList(String commaSeparatedList)
  9. toCommaDelimited(List values)