Java Utililty Methods Comma Separated List

List of utility methods to do Comma Separated List

Description

The list of methods to do Comma Separated List are organized into topic(s).

Method

StringgetCommaSeparatedList(List list)
Turn a list of Strings into a concatenated string of filenames
StringBuffer sb = new StringBuffer();
for (Iterator<String> i = list.iterator(); i.hasNext();) {
    sb.append(i.next());
    if (i.hasNext()) {
        sb.append(",");
return sb.toString();
...
StringgetCommaSeparatedListOfString(Collection list)
get Comma Separated List Of String
return getCommaSeparatedListOfString(list, "(", ")", true);
StringgetCommaSeparatedValue(List> enumList)
Gets the comma separated value.
StringBuffer stringBuffer = new StringBuffer();
for (Enum<?> element : enumList) {
    if (stringBuffer.length() != 0) {
        stringBuffer.append(",");
    stringBuffer.append(element.name());
return stringBuffer.toString();
...
StringgetCommaSeparatedValues(List values)
Returns the specified list of values as a String representing a comma-separated list of values.
if (null == values || values.size() == 0)
    return ""; 
StringBuilder b = new StringBuilder("'").append(values.get(0)).append("'"); 
for (int i = 1, len = values.size(); i < len; i++) {
    b.append(",'").append(values.get(i)).append("'"); 
return b.toString();
StringgetListAsCommaSeparatedString(List list)
get List As Comma Separated String
if (list == null || list.isEmpty()) {
    return null;
StringBuilder sb = new StringBuilder();
for (String key : list) {
    sb.append(key);
    sb.append(",");
sb.setLength(sb.length() - 1);
return sb.toString();
StringgetStringList(List list, boolean useComma, boolean useBrackets, String comma)
List the toString out put of the objects in the List that can be comma separated.
StringBuffer buffer = new StringBuffer();
if (!useComma) {
    comma = "";
if (list != null) {
    if (useBrackets) {
        buffer.append("(");
    for (int i = 0; i < list.size(); i++) {
        buffer.append(list.get(i)).append((i < list.size() - 1) ? comma : "");
    if (useBrackets) {
        buffer.append(")");
return buffer.toString();
ListgetStringListFromCommaSeparatedString(String input)
get String List From Comma Separated String
List<String> list = new ArrayList<String>();
if (!input.isEmpty()) {
    String[] toArray = input.split(",");
    list.addAll(Arrays.asList(toArray));
return list;
StringhumanReadableCommandLineOutput(List arguments)
Build a human readable command line from the arguments set by the plugin
String debugOutput = "";
for (String argument : arguments) {
    debugOutput += argument + " ";
return debugOutput.trim();
StringimplodeCommaAnd(List list, String comma, String and)
implode Comma And
if (list.size() == 0)
    return "";
if (list.size() == 1)
    return list.get(0);
String lastItem = list.get(list.size() - 1);
String nextToLastItem = list.get(list.size() - 2);
String merge = nextToLastItem + and + lastItem;
list.set(list.size() - 2, merge);
...
StringlistToComma(List list)
list To Comma
StringBuilder sb = new StringBuilder();
for (int i = 0; i < list.size(); i++) {
    sb.append(String.valueOf(list.get(i)));
    if (i < list.size() - 1) {
        sb.append(",");
return sb.toString();
...