Here you can find the source of iterableToString(String separator, Iterable
public static final <T> String iterableToString(String separator, Iterable<T> collection)
//package com.java2s; import java.util.Iterator; public class Main { public static final <T> // String iterableToString(String separator, Iterable<T> collection) { if (collection != null) return iterableToString(separator, collection.iterator()); return ""; }//www. ja v a 2s.c o m public static final <T> // String iterableToString(String separator, Iterator<T> iterator) { StringBuilder sb = new StringBuilder(); while (iterator.hasNext()) { T item = iterator.next(); if (item != null) { String appendable = item.toString(); sb.append(appendable); if (iterator.hasNext()) sb.append(separator); } } return sb.toString(); } public static final <T> // String iterableToString(String separator, T... collection) { StringBuilder sb = new StringBuilder(); if (collection != null) for (int i = 0; i != collection.length; i++) { T item = collection[i]; if (item != null) { String appendable = item.toString(); sb.append(appendable); if (i != collection.length - 1) sb.append(separator); } } return sb.toString(); } }