Java Iterable to String toString(Iterable iterable, String separator)

Here you can find the source of toString(Iterable iterable, String separator)

Description

to String

License

Open Source License

Declaration

public static <T> String toString(Iterable<T> iterable, String separator) 

Method Source Code

//package com.java2s;
/*// w ww.  ja  va2  s .c  om
 * Carrot2 project.
 *
 * Copyright (C) 2002-2016, Dawid Weiss, Stanis?aw Osi?ski.
 * All rights reserved.
 *
 * Refer to the full license file "carrot2.LICENSE"
 * in the root folder of the repository checkout or at:
 * http://www.carrot2.org/carrot2.LICENSE
 */

import java.util.Iterator;

public class Main {
    public static <T> String toString(Iterable<T> iterable, String separator) {
        final StringBuilder stringBuilder = new StringBuilder();

        for (final Iterator<T> iterator = iterable.iterator(); iterator.hasNext();) {
            final T object = iterator.next();
            stringBuilder.append(object);
            if (iterator.hasNext()) {
                stringBuilder.append(separator);
            }
        }

        return stringBuilder.toString();
    }
}

Related

  1. toString(Iterable objects, String sep)
  2. toString(Iterable it, String separator)
  3. toString(Iterable names)
  4. toString(Iterable iterable)
  5. toString(Iterable strs)