Java Collection to String toString(Collection collection)

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

Description

to String

License

Open Source License

Declaration

public static <T> String toString(Collection<T> collection) 

Method Source Code

//package com.java2s;
import java.util.Collection;

public class Main {
    public static <T> String toString(Collection<T> collection) {
        StringBuilder stringBuilder = new StringBuilder("[");
        boolean first = true;
        for (T t : collection) {
            if (!first) {
                stringBuilder.append(',');
            } else {
                first = true;//from  ww w  .j  ava 2 s.co m
            }
            if (t == null) {
                stringBuilder.append("null");
            } else {
                stringBuilder.append(t.toString());
            }
        }
        stringBuilder.append(']');
        return stringBuilder.toString();
    }
}

Related

  1. toString(Collection bytes, Collection result)
  2. toString(Collection collection)
  3. toString(Collection strings)
  4. toString(Collection a, String begStr, String sepStr, String endStr)
  5. toString(Collection collection)
  6. toString(Collection collection)
  7. toString(Collection collection)
  8. toString(Collection collection, String divider)
  9. toString(Collection list, String delimeter)

  10. HOME | Copyright © www.java2s.com 2016