Here you can find the source of join(CharSequence delimiter, Iterable tokens)
Parameter | Description |
---|---|
tokens | an array objects to be joined. Strings will be formed from the objects by calling object.toString(). |
public static String join(CharSequence delimiter, Iterable tokens)
//package com.java2s; import java.util.Iterator; public class Main { /**/*from w w w. j av a 2 s . c o m*/ * Returns a string containing the tokens joined by delimiters. * * @param tokens an array objects to be joined. Strings will be formed from * the objects by calling object.toString(). */ public static String join(CharSequence delimiter, Iterable tokens) { StringBuilder sb = new StringBuilder(); Iterator<?> it = tokens.iterator(); if (it.hasNext()) { sb.append(it.next()); while (it.hasNext()) { sb.append(delimiter); sb.append(it.next()); } } return sb.toString(); } }