Java Collection to String collectionToString(Collection list)

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

Description

collection To String

License

Apache License

Declaration

public static <T> String collectionToString(Collection<T> list) 

Method Source Code

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

import java.util.*;

public class Main {
    public static <T> String collectionToString(Collection<T> list,
            String splitter) {//from  w  w  w.  j  av a 2 s  . co  m
        if (list.size() == 0)
            return "";

        Iterator iterator = list.iterator();

        String value = iterator.next().toString();
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(value);

        while (iterator.hasNext()) {
            value = iterator.next().toString();
            stringBuilder.append(splitter);
            stringBuilder.append(value);
        }
        return stringBuilder.toString();
    }

    public static <T> String collectionToString(Collection<T> list) {
        return collectionToString(list, ", ");
    }
}

Related

  1. collectionToString(Collection collection)
  2. collectionToString(Collection collection)
  3. collectionToString(Collection collection)
  4. collectionToString(Collection col, String sep)
  5. collectionToString(Collection collection)
  6. collectionToString(final Collection collection, final String recordSeparator)
  7. collectionToString(final Collection aCol, final String aSepLines)
  8. collectionToString(final Collection c)
  9. collectionToString(final Collection collection, final String separator)