Java Iterator Join join(Iterator iterator, String separator)

Here you can find the source of join(Iterator iterator, String separator)

Description

Joins the elements of the provided Iterator into a single String containing the provided elements.

License

BSD License

Declaration

public static String join(Iterator iterator, String separator) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright Duke Comprehensive Cancer Center and SemanticBits
 * //from   w ww . j a  v a 2 s.c om
 * Distributed under the OSI-approved BSD 3-Clause License.
 * See http://ncip.github.com/c3pr/LICENSE.txt for details.
 ******************************************************************************/

import java.util.Iterator;

public class Main {
    /**
     * <p>Joins the elements of the provided <code>Iterator</code> into
     * a single String containing the provided elements.</p>
     **/
    public static String join(Iterator iterator, String separator) {
        if (separator == null) {
            separator = "";
        }
        StringBuffer buf = new StringBuffer(256); // Java default is 16, probably too small
        while (iterator.hasNext()) {
            buf.append(iterator.next());
            if (iterator.hasNext()) {
                buf.append(separator);

            }
        }
        return buf.toString();
    }
}

Related

  1. join(Iterator iterator, String s)
  2. join(Iterator iterator, String separator)
  3. join(Iterator objects, String separator)
  4. join(Iterator iterator, String separator)
  5. join(Iterator iterator)
  6. join(String delimiter, Iterator iterator)