Java Comma Separated List getCommaSeparatedValues(List values)

Here you can find the source of getCommaSeparatedValues(List values)

Description

Returns the specified list of values as a String representing a comma-separated list of values.

License

Open Source License

Parameter

Parameter Description
values a List of <code>String</code> values

Return

a String representing a comma-separated list of values, an empty String if the specified list is null or empty

Declaration

public static String getCommaSeparatedValues(List<String> values) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2011 neXtep Software and contributors.
 * All rights reserved.//w ww .  j  ava2s.  c  o m
 *
 * This file is part of neXtep designer.
 *
 * NeXtep designer 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 3 of the License, or any later version.
 *
 * NeXtep designer 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Contributors:
 *     neXtep Softwares - initial API and implementation
 *******************************************************************************/

import java.util.List;

public class Main {
    /**
     * Returns the specified list of values as a <code>String</code> representing a comma-separated
     * list of values.
     * 
     * @param values a {@link List} of <code>String</code> values
     * @return a <code>String</code> representing a comma-separated list of values, an empty
     *         <code>String</code> if the specified list is <code>null</code> or empty
     */
    public static String getCommaSeparatedValues(List<String> values) {
        if (null == values || values.size() == 0)
            return ""; //$NON-NLS-1$

        StringBuilder b = new StringBuilder("'").append(values.get(0)).append("'"); //$NON-NLS-1$ //$NON-NLS-2$
        for (int i = 1, len = values.size(); i < len; i++) {
            b.append(",'").append(values.get(i)).append("'"); //$NON-NLS-1$ //$NON-NLS-2$
        }

        return b.toString();
    }
}

Related

  1. getCommaSeparatedList(Collection stringValues)
  2. getCommaSeparatedList(List list)
  3. getCommaSeparatedList(List list)
  4. getCommaSeparatedListOfString( Collection list)
  5. getCommaSeparatedValue(List> enumList)
  6. getListAsCommaSeparatedString(List list)
  7. getStringList(List list, boolean useComma, boolean useBrackets, String comma)
  8. getStringListFromCommaSeparatedString(String input)
  9. humanReadableCommandLineOutput(List arguments)