Java tutorial
//package com.java2s; import java.util.Collection; import java.util.List; public class Main { public static <T> String concatUpto(List<T> col, int toIndex, String separator) { return concat(col, 0, toIndex, separator); } public static <T> String concat(Collection<T> col, String separator) { StringBuilder result = new StringBuilder(); for (T e : col) { String s = e.toString(); if (!s.isEmpty()) { if (result.length() > 0) result.append(separator); result.append(s); } } return result.toString(); } public static <T> String concat(List<T> col, int fromIndex, int toIndex, String separator) { if (fromIndex < 0 || toIndex > col.size() || fromIndex > toIndex) return ""; return concat(col.subList(fromIndex + 1, toIndex), separator); } }