Java List to String toString(List list)

Here you can find the source of toString(List list)

Description

Builds a string containing the names of each list element separated by comma.

License

Open Source License

Parameter

Parameter Description
list The list containing the elements.

Return

The string containing the names of each list element separated by comma.

Declaration

public static String toString(List<? extends Object> list) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Iterator;
import java.util.List;

public class Main {
    /**/*w  ww.j a v a 2 s .c  o  m*/
     * Builds a string containing the names of each list element separated
     * by comma.
     * 
     * @param list The list containing the elements.
     * 
     * @return The string containing the names of each list element separated
     * by comma.
     */
    public static String toString(List<? extends Object> list) {
        String result = "";
        for (Iterator<? extends Object> it = list.iterator(); it.hasNext();) {
            Object obj = it.next();
            if (it.hasNext()) {
                result += obj.toString() + ", ";
            } else {
                result += obj.toString();
            }
        }
        return result;
    }
}

Related

  1. toString(final List list, char delimiter)
  2. toString(final Object[] list)
  3. toString(List arguments)
  4. toString(List l)
  5. toString(List list)
  6. toString(List objects)
  7. toString(List col)
  8. toString(List coll, char delimiter)
  9. toString(List list)