Here you can find the source of getCommaSeparatedValues(List
String
representing a comma-separated list of values.
Parameter | Description |
---|---|
values | a List of <code>String</code> values |
String
representing a comma-separated list of values, an empty String
if the specified list is null
or empty
public static String getCommaSeparatedValues(List<String> values)
//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(); } }