Here you can find the source of join(Iterable
public static <T> String join(Iterable<T> values, String separator)
//package com.java2s; /**//from w w w .j av a 2 s .co m * Copyright 2010 Bing Ran<bing_ran@hotmail.com> * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0. * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.Arrays; import java.util.Iterator; public class Main { public static <T> String join(Iterable<T> values, String separator) { if (values == null) { return ""; } Iterator<T> iter = values.iterator(); if (!iter.hasNext()) { return ""; } StringBuffer toReturn = new StringBuffer(String.valueOf(iter.next())); while (iter.hasNext()) { toReturn.append(separator + String.valueOf(iter.next())); } return toReturn.toString(); } public static String join(String[] values, String separator) { return (values == null) ? "" : join(Arrays.asList(values), separator); } }