Here you can find the source of join(String delimiter, Iterator> iterator)
public static String join(String delimiter, Iterator<?> iterator)
//package com.java2s; import java.util.Iterator; public class Main { public static final String EMPTY_STRING = ""; public static <T> String join(String delimiter, T... values) { if (delimiter == null) { delimiter = EMPTY_STRING;//from www . ja va 2 s .co m } if (values.length == 0) { return EMPTY_STRING; } else if (values.length == 1) { return String.valueOf(values[0]); } else if (values.length == 2) { return String.valueOf(values[0]) + delimiter + String.valueOf(values[1]); } StringBuilder joined = new StringBuilder(); joined.append(String.valueOf(values[0])); for (int i = 1; i < values.length; i++) { joined.append(delimiter).append(values[i]); } return joined.toString(); } public static String join(String delimiter, Iterator<?> iterator) { if (delimiter == null) { delimiter = EMPTY_STRING; } if (!iterator.hasNext()) { return EMPTY_STRING; } Object first = iterator.next(); if (!iterator.hasNext()) { return String.valueOf(first); } StringBuilder joined = new StringBuilder(); joined.append(first); while (iterator.hasNext()) { joined.append(delimiter).append(iterator.next()); } return joined.toString(); } }