Here you can find the source of toString(Iterable
public static <T> String toString(Iterable<T> iterable, String separator)
//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(); } }