Java Collection Print printCollection(Collection c)

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

Description

Utility method to print a collection.

License

Open Source License

Parameter

Parameter Description
c a parameter

Return

String

Declaration

public static String printCollection(Collection c) 

Method Source Code

//package com.java2s;

import java.util.Collection;

import java.util.Iterator;

public class Main {
    /**/*from  ww w  .java  2s. c  om*/
     * Utility method to print a collection.
     * @param c
     * @return String
     */
    public static String printCollection(Collection c) {
        if (c != null) {
            StringBuffer sb = new StringBuffer("[");
            Iterator itr = c.iterator();
            while (itr.hasNext()) {
                sb.append(itr.next());
                if (itr.hasNext()) {
                    sb.append(", ");
                }
            }
            sb.append("]");
            return sb.toString();
        } else {
            return "[null]";
        }
    }
}

Related

  1. print(Collection c, String separator)
  2. print(Collection c)
  3. print(Collection coll)
  4. print(Collection elements)
  5. print(java.util.Collection collection)
  6. printCollection(Collection col)
  7. printCollection(Collection collection)
  8. printCollection(Collection l)
  9. printCollection(Collection col)