Java tutorial
//package com.java2s; import java.util.Iterator; public class Main { public static String join(Iterator<String> strings, String sep) { if (!strings.hasNext()) return ""; String start = strings.next(); if (!strings.hasNext()) // only one, avoid builder return start; StringBuilder sb = new StringBuilder(64).append(start); while (strings.hasNext()) { sb.append(sep); sb.append(strings.next()); } return sb.toString(); } }