Java Collection to String toString(Collection collection)

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

Description

Method description

License

Open Source License

Parameter

Parameter Description
collection a parameter

Declaration

public static String toString(Collection<? extends Object> collection) 

Method Source Code

//package com.java2s;

import java.util.Collection;

import java.util.Iterator;

public class Main {
    /**/*from   w w w  .  ja va2s.  c om*/
     * Method description
     *
     *
     * @param collection
     *
     * @return
     */
    public static String toString(Collection<? extends Object> collection) {
        StringBuilder sb = new StringBuilder();

        if (collection != null) {
            Iterator<? extends Object> it = collection.iterator();

            while (it.hasNext()) {
                sb.append(it.next());

                if (it.hasNext()) {
                    sb.append(", ");
                }
            }
        }

        return sb.toString();
    }

    /**
     * Method description
     *
     *
     * @param byteValue
     *
     * @return
     */
    public static String toString(byte[] byteValue) {
        StringBuilder buffer = new StringBuilder();

        for (int i = 0; i < byteValue.length; i++) {
            int x = byteValue[i] & 0xff;

            if (x < 16) {
                buffer.append('0');
            }

            buffer.append(Integer.toString(x, 16));
        }

        return buffer.toString();
    }
}

Related

  1. toString(Collection c, String start, String separator, String end)
  2. toString(Collection collection, String separator, int fixedLength)
  3. toString(Collection objects)
  4. toString(Collection setOfTests)
  5. toString(Collection softwareTags)
  6. toString(Collection collection, String prefix, String suffix)
  7. toString(Collection c)
  8. toString(Collection c)
  9. toString(Collection collection)