Java Collection to String collectionToString(Collection c)

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

Description

collection To String

License

Open Source License

Declaration

public static String collectionToString(Collection<?> c) 

Method Source Code

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

import java.util.*;

public class Main {
    public static String collectionToString(Collection<?> c) {
        StringBuilder sb = new StringBuilder("[");
        Iterator<?> i = c.iterator();
        while (i.hasNext()) {
            Object o = i.next();//from   w  ww .  ja v  a 2  s  . com
            if (o == null)
                sb.append("null");
            else if (o == c)
                sb.append("(this Collection)");
            else
                sb.append(o.toString());
            if (i.hasNext())
                sb.append(", ");
        }
        sb.append("]");
        return sb.toString();
    }

    public static String toString(Object o) {
        return String.valueOf(o);
    }
}

Related

  1. collectionToString(Collection set)
  2. collectionToString(Collection c)
  3. collectionToString(Collection collection, String delimiter)
  4. collectionToString(Collection collection, String seperator)
  5. collectionToString(Collection list, String delimiter)
  6. collectionToString(Collection c)
  7. collectionToString(Collection c)
  8. collectionToString(Collection c)
  9. collectionToString(Collection c, String separator)