Java Iterable Join join(StringBuilder buf, Iterable values, String separator)

Here you can find the source of join(StringBuilder buf, Iterable values, String separator)

Description

append values to buf separated with the specified separator

License

Apache License

Declaration

public static void join(StringBuilder buf, Iterable<?> values, String separator) 

Method Source Code

//package com.java2s;
/*/* w w  w.j  av  a 2  s  . c o  m*/
 *  Copyright Gergely Nagy <greg@webhejj.hu>
 *
 *  Licensed under the Apache License, Version 2.0; 
 *  you may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 */

import java.util.Iterator;

public class Main {
    /** append values to buf separated with the specified separator */
    public static void join(StringBuilder buf, Iterable<?> values, String separator) {
        for (Iterator<?> i = values.iterator(); i.hasNext();) {
            buf.append(i.next());
            if (i.hasNext()) {
                buf.append(separator);
            }
        }
    }

    /** @return string values in the list separated by the specified <code>separator</code> */
    public static String join(Iterable<?> values, String separator) {
        StringBuilder buf = new StringBuilder();
        join(buf, values, separator);
        return buf.toString();
    }
}

Related

  1. join(String separator, Iterable elements)
  2. join(String separator, Iterable objects)
  3. join(String separator, Iterable args)
  4. join(String seperator, Iterator objects)
  5. join(String seprator, Iterable coll)
  6. joinIterableOnComma(Iterable iterable)
  7. joinIterables(final Iterable... iterables)
  8. joinStr(CharSequence glue, Iterable parts)
  9. joinStrings(Iterable arr, String glue)