Java Iterable to String iterableToString(Iterable itrbl)

Here you can find the source of iterableToString(Iterable itrbl)

Description

iterable To String

License

BSD License

Declaration

public static <E> String iterableToString(Iterable<E> itrbl) 

Method Source Code

//package com.java2s;
// Licensed under the Modified BSD Licence; see COPYING for details.

public class Main {
    public static <E> String iterableToString(Iterable<E> itrbl) {
        StringBuffer buff = new StringBuffer();
        buff.append("[ ");
        boolean first = true;
        for (E elem : itrbl) {
            if (!first) {
                buff.append(", ");
            }//from  w ww.j  a  va 2  s.com
            first = false;
            buff.append(elem);
        }
        buff.append(" ]");
        return buff.toString();
    }

    /** Returns <code>"null"</code> if the argument <code>o</code> is
    null, and <code>o.toString()</code> otherwise. */
    public static String toString(Object o) {
        if (o == null)
            return "null";
        return o.toString();
    }
}

Related

  1. iterableAsString(Iterable chars)
  2. iterableToString(Iterable iterable)
  3. iterableToString(Iterable list)
  4. iterableToString(Iterable charSequenceIterable)
  5. iterableToString(Iterable objects, int limit)
  6. toString(final Iterable iterable, final CharSequence delimiter)
  7. toString(Iterable c, String delim, String prefix, String suffix)
  8. toString(Iterable objects, String sep)