Java Iterable appendTo(StringBuilder appendable, Iterable parts, CharSequence separator)

Here you can find the source of appendTo(StringBuilder appendable, Iterable parts, CharSequence separator)

Description

append To

License

Apache License

Declaration

private static StringBuilder appendTo(StringBuilder appendable,
            Iterable<?> parts, CharSequence separator) 

Method Source Code

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

import java.util.Iterator;

public class Main {
    private static StringBuilder appendTo(StringBuilder appendable,
            Iterable<?> parts, CharSequence separator) {
        Iterator<?> iterator = parts.iterator();
        if (iterator.hasNext()) {
            appendable.append(toString(iterator.next()));
            while (iterator.hasNext()) {
                appendable.append(separator);
                appendable.append(toString(iterator.next()));
            }/*from w  w w .j a  va  2 s .  c om*/
        }
        return appendable;
    }

    private static CharSequence toString(Object part) {
        return (part instanceof CharSequence) ? (CharSequence) part : part
                .toString();
    }
}

Related

  1. commafy(Iterable col, StringBuilder builder)
  2. containsSame(Iterable coll, Object obj)
  3. convertIterable(final Iterable> iterables)
  4. createDelimitedString(Iterable iterable, String delimiter)