Java Iterable to String toString(Iterable it, String separator)

Here you can find the source of toString(Iterable it, String separator)

Description

to String

License

Apache License

Declaration

public static String toString(Iterable<?> it, String separator) 

Method Source Code

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

import java.util.Iterator;

public class Main {
    public static String toString(Object object) {
        if (object == null) {
            return "null";
        }//  w ww . j ava  2 s.c o  m
        return object.toString();
    }

    public static String toString(Iterable<?> it, String separator) {
        final StringBuilder builder = new StringBuilder();
        final Iterator<?> iterator = it.iterator();
        while (iterator.hasNext()) {
            builder.append(iterator.next().toString());
            if (iterator.hasNext()) {
                builder.append(separator);
            }
        }
        return builder.toString();
    }
}

Related

  1. iterableToString(Iterable itrbl)
  2. iterableToString(Iterable objects, int limit)
  3. toString(final Iterable iterable, final CharSequence delimiter)
  4. toString(Iterable c, String delim, String prefix, String suffix)
  5. toString(Iterable objects, String sep)
  6. toString(Iterable names)
  7. toString(Iterable iterable)
  8. toString(Iterable strs)
  9. toString(Iterable iterable, String separator)