Java Collection to String collectionToString(Iterable c)

Here you can find the source of collectionToString(Iterable c)

Description

Create a string representation of an iterable collection

License

Creative Commons License

Parameter

Parameter Description
T the collection type
c the collection

Declaration

public static <T> String collectionToString(Iterable<T> c) 

Method Source Code

//package com.java2s;
//License from project: Creative Commons License 

import java.util.Iterator;

public class Main {
    /**// ww  w . java  2s. com
     * Create a string representation of an iterable collection
     * @param <T> the collection type
     * @param c the collection
     * @return
     */
    public static <T> String collectionToString(Iterable<T> c) {
        StringBuilder b = new StringBuilder();
        b.append("[");
        Iterator<T> it = c.iterator();
        while (it.hasNext()) {
            b.append(it.next());
            if (it.hasNext())
                b.append(",");
        }
        b.append("]");
        return b.toString();
    }
}

Related

  1. collectionToString(final Collection aCol, final String aSepLines)
  2. collectionToString(final Collection c)
  3. collectionToString(final Collection collection, final String separator)
  4. collectionToString(final Collection elements, final String separator)
  5. collectionToString(final String separator, final Collection coll)
  6. collectionToString(Object[] objects)
  7. collectionToString(String prefix, Collection list)
  8. collectionToStringArray(Collection holder)
  9. collectionToStringArray(Collection objs)