Java tutorial
//package com.java2s; //License from project: Apache License import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Iterator; import java.util.List; public class Main { public static <V> String join(String seprator, Object... arr) { return join(seprator, asList(arr)); } public static <V> String join(String seprator, Iterable<V> coll) { return join("", seprator, coll); } public static <V> String join(String prefix, String seprator, Iterable<V> coll) { return join(prefix, false, seprator, coll); } public static <V> String join(String prefix, boolean bQuote, String seprator, Iterable<V> coll) { StringBuffer sb = new StringBuffer(prefix); for (Iterator<V> iterator = coll.iterator(); iterator.hasNext();) { V v = iterator.next(); if (bQuote) sb.append("'"); sb.append(v.toString()); if (bQuote) sb.append("'"); if (iterator.hasNext()) sb.append(seprator); } return sb.toString(); } public static <T> List<T> asList(T... objs) { return Arrays.asList(objs); } public static <T> List<T> asList(Collection<T> coll) { return new ArrayList<T>(coll); } }