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;

import java.util.Collection;
import java.util.Iterator;

public class Main {
    public static String collectionToString(Collection c) {
        StringBuffer buff = new StringBuffer();
        int i = 0;
        int size = c.size();
        for (Iterator iter = c.iterator(); iter.hasNext();) {
            Object object = iter.next();
            if (size > 1 && i == (size - 1)) {
                buff.append("and ");
            }/*from   w  w  w.ja va2  s  .  com*/
            buff.append(object);
            if (i < (size - 1)) {
                if (size > 2) {
                    buff.append(", ");
                } else {
                    buff.append(" ");
                }
            }
            i++;
        }
        return buff.toString();

    }
}

Related

  1. collectionToStr(Collection collection)
  2. CollectionToStr(Collection coll)
  3. collectionToStr(Collection collection)
  4. collectionToString( Collection collection)
  5. collectionToString(@SuppressWarnings("rawtypes") Collection coll)
  6. collectionToString(Collection c, String delim)
  7. collectionToString(Collection c, String spilt)
  8. collectionToString(Collection col)
  9. collectionToString(Collection coll)