Here you can find the source of join(String glue, Iterable> tokens)
static String join(String glue, Iterable<?> tokens)
//package com.java2s; //License from project: Apache License import java.util.Iterator; import java.util.Map; public class Main { static String join(String glue, Iterable<?> tokens) { final StringBuilder sb = new StringBuilder(); final Iterator<?> iterator = tokens.iterator(); while (iterator.hasNext()) { sb.append(iterator.next());/* ww w . j a v a 2 s .c om*/ if (iterator.hasNext()) { sb.append(glue); } } return sb.toString(); } static String join(String glue, Map<String, String> tokens, String tokensGlue) { final StringBuilder sb = new StringBuilder(); final Iterator<Map.Entry<String, String>> iterator = tokens .entrySet().iterator(); while (iterator.hasNext()) { final Map.Entry<String, String> entry = iterator.next(); sb.append(entry.getKey()).append(tokensGlue) .append(entry.getValue()); if (iterator.hasNext()) { sb.append(glue); } } return sb.toString(); } }