Here you can find the source of join(StringBuilder buf, Iterable> values, String separator)
public static void join(StringBuilder buf, Iterable<?> values, String separator)
//package com.java2s; /*/* w w w.j av a 2 s . c o m*/ * Copyright Gergely Nagy <greg@webhejj.hu> * * Licensed under the Apache License, Version 2.0; * you may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 */ import java.util.Iterator; public class Main { /** append values to buf separated with the specified separator */ public static void join(StringBuilder buf, Iterable<?> values, String separator) { for (Iterator<?> i = values.iterator(); i.hasNext();) { buf.append(i.next()); if (i.hasNext()) { buf.append(separator); } } } /** @return string values in the list separated by the specified <code>separator</code> */ public static String join(Iterable<?> values, String separator) { StringBuilder buf = new StringBuilder(); join(buf, values, separator); return buf.toString(); } }