Here you can find the source of join(List extends CharSequence> s, String delimiter)
public static String join(List<? extends CharSequence> s, String delimiter)
//package com.java2s; import java.util.Iterator; import java.util.List; public class Main { public static String join(List<? extends CharSequence> s, String delimiter) { int capacity = 0; int delimLength = delimiter.length(); Iterator<? extends CharSequence> iter = s.iterator(); if (iter.hasNext()) { capacity += iter.next().length() + delimLength; }//from w w w .j a v a 2 s . c o m StringBuilder buffer = new StringBuilder(capacity); iter = s.iterator(); if (iter.hasNext()) { buffer.append(iter.next()); while (iter.hasNext()) { buffer.append(delimiter); buffer.append(iter.next()); } } return buffer.toString(); } }