Java List to String listToString(List items)

Here you can find the source of listToString(List items)

Description

Return a string with the listed items separated by ", "

License

Open Source License

Parameter

Parameter Description
items a parameter

Return

a string

Declaration

public static String listToString(List<?> items) 

Method Source Code

//package com.java2s;

import java.util.List;

public class Main {
    /**// w  w  w.j  a va  2s.c om
     * Return a string with the listed items separated by ", "
     * @param items
     * @return a string
     */
    public static String listToString(List<?> items) {
        return listToString(items, ", ");
    }

    /**
     * Return a string with the listed items separated by the given separator
     * @param items
     * @param separator
     * @return a string
     */
    public static String listToString(List<?> items, String separator) {
        boolean doneOne = false;
        final StringBuffer sb = new StringBuffer();
        for (Object o : items) {
            if (doneOne)
                sb.append(separator);
            doneOne = true;

            sb.append(o.toString());
        }
        return sb.toString();
    }
}

Related

  1. listToString(List list)
  2. listToString(List list, String delim)
  3. listToString(List list, String header, String separator, String footer)
  4. ListToString(List lista)
  5. listToString(List collection)
  6. listToString(List l, String delim)
  7. listToString(List l, String sep)
  8. listToString(List list)
  9. listToString(List list)