Java Iterator asStringOn(StringBuffer sb, Iterator iter, String separator)

Here you can find the source of asStringOn(StringBuffer sb, Iterator iter, String separator)

Description

Copies the elements returned by the iterator onto the string buffer each delimited by the separator.

License

BSD License

Parameter

Parameter Description
sb StringBuffer
iter Iterator
separator String

Declaration

public static void asStringOn(StringBuffer sb, Iterator iter,
        String separator) 

Method Source Code

//package com.java2s;
/**/*from   w ww.  ja  v a2 s . c om*/
 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
 */

import java.util.Iterator;

public class Main {
    /**
     * Copies the elements returned by the iterator onto the string buffer
     * each delimited by the separator.
     *
     * @param sb StringBuffer
     * @param iter Iterator
     * @param separator String
     */
    public static void asStringOn(StringBuffer sb, Iterator iter,
            String separator) {

        if (!iter.hasNext())
            return;

        sb.append(iter.next());

        while (iter.hasNext()) {
            sb.append(separator);
            sb.append(iter.next());
        }
    }
}

Related

  1. areEqual(final Iterator a, final Iterator b)
  2. areEqual(final Iterator ittyA, final Iterator ittyB)
  3. asArray(T[] arr, Iterator itr)
  4. asList(final Iterator iterator)
  5. asList(Iterator it)
  6. cast(Iterator p)
  7. closeIterator(Iterator iterator)
  8. compareRanges(final Iterator i, final Iterator j)
  9. concatinateElements(Iterator it)