Java Collection to String toString(final Collection collection)

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

Description

to String

License

Apache License

Declaration

public static String toString(final Collection<?> collection) 

Method Source Code


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

import java.util.Collection;

public class Main {
    public static String toString(final Object[] objects) {
        if (objects == null)
            return "null";
        final StringBuilder sb = new StringBuilder("{");
        boolean isFirst = true;
        for (final Object object : objects) {
            if (!isFirst)
                sb.append(',');
            else// www  . j  a v a2  s .  c  om
                isFirst = false;
            sb.append(object);
        }
        sb.append('}');
        return sb.toString();
    }

    public static String toString(final Collection<?> collection) {
        if (collection == null)
            return "null";
        final StringBuilder sb = new StringBuilder("{");
        boolean isFirst = true;
        for (final Object object : collection) {
            if (!isFirst)
                sb.append(',');
            else
                isFirst = false;
            sb.append(object);
        }
        sb.append('}');
        return sb.toString();
    }
}

Related

  1. toString(Collection collection)
  2. toString(Collection collection)
  3. toString(Collection collection)
  4. toString(Collection collection, String divider)
  5. toString(Collection list, String delimeter)
  6. toString(final Collection collection)
  7. toString(final Collection collection, final String separator)
  8. toString(final Collection objs)
  9. toString(final Collection values)