Java Collection to String collectionToStr(Collection collection)

Here you can find the source of collectionToStr(Collection collection)

Description

collection To Str

License

Apache License

Declaration

public static String collectionToStr(Collection<?> collection) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Collection;

public class Main {
    public static String collectionToStr(Collection<?> collection) {
        return collectionToStr(collection, null, null, null, true);
    }/*from   w ww. ja  va 2 s. c  om*/

    public static String collectionToStr(Collection<?> collection, Object separator) {
        return collectionToStr(collection, separator, null, null, true);
    }

    public static String collectionToStr(Collection<?> collection, Object beginBlock, Object endBlock) {
        return collectionToStr(collection, null, beginBlock, endBlock, true);
    }

    public static String collectionToStr(Collection<?> collection, Object separator, Object beginBlock,
            Object endBlock) {
        return collectionToStr(collection, separator, beginBlock, endBlock, true);
    }

    public static String collectionToStr(Collection<?> collection, Object separator, Object beginBlock,
            Object endBlock, boolean useConvert) {

        if (collection == null)
            return null;
        if (separator == null)
            separator = ',';

        StringBuilder sb = new StringBuilder();
        if (beginBlock != null)
            sb.append(beginBlock);
        boolean first = true;
        for (Object ob : collection) {
            if (!first)
                sb.append(separator);
            first = false;

            if (!useConvert)
                sb.append(ob);
            else
                sb.append(ob);
        }
        if (endBlock != null)
            sb.append(endBlock);
        return sb.toString();
    }
}

Related

  1. collectionToDelimitedString(Collection col, String del)
  2. collectionToDelimitedString(Collection coll, String delim)
  3. collectionToDelimitedString(Collection coll, String delim)
  4. collectionToDelimitedString(Collection coll, String delim, String prefix, String suffix)
  5. collectionToDelimitedString(Collection values, String delimiter)
  6. CollectionToStr(Collection coll)
  7. collectionToStr(Collection collection)
  8. collectionToString( Collection collection)
  9. collectionToString(@SuppressWarnings("rawtypes") Collection coll)