Java Iterable Join join(final Iterable iterable, final String joinString)

Here you can find the source of join(final Iterable iterable, final String joinString)

Description

join

License

Open Source License

Declaration

public static String join(final Iterable<String> iterable, final String joinString) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2012 eBay Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*from  w w  w .  j  av  a 2  s.  c o  m*/
 *     eBay Inc. - initial API and implementation
 *******************************************************************************/

import java.util.Iterator;

public class Main {
    public static String join(final Iterable<String> iterable, final String joinString) {
        return join(iterable.iterator(), joinString);
    }

    public static String join(final Iterator<String> iterator, final String joinString) {
        final StringBuilder buf = new StringBuilder();
        join(iterator, joinString, buf);
        final String resultString = buf.toString();
        return resultString;
    }

    public static void join(final Iterable<String> iterator, final String joinString,
            final StringBuilder stringStream) {
        join(iterator.iterator(), joinString, stringStream);
    }

    public static void join(final Iterator<String> iterator, final String joinString,
            final StringBuilder stringStream) {
        while (iterator.hasNext()) {
            final String string = iterator.next();
            stringStream.append(string);
            if (iterator.hasNext()) {
                stringStream.append(joinString);
            }
        }
    }
}

Related

  1. join(final Iterable iterable, final String separator)
  2. join(final Iterable... iterables)
  3. join(final Iterable items, final String separator)
  4. join(final Iterable iterable, final String separator)
  5. join(final Iterable container)
  6. join(final Iterable objs, final String delimiter)
  7. join(final Iterable objs, final String delimiter)
  8. join(final Iterable source)
  9. join(final Iterable... iterables)