Java tutorial
//package com.java2s; import java.util.Arrays; import java.util.Collection; public class Main { @Deprecated public static String toString(Collection collection, String separator) { return join(collection, separator); } @Deprecated public static String toString(Object[] objs, String separator) { return join(objs, separator); } public static <T> String join(Collection<T> col, String separator) { String ret = ""; if (col != null && col.size() > 0) { for (Object x : col) { if (x instanceof java.lang.String) { ret += separator + (String) x; } else { ret += separator + x.toString(); } } } return ret.replaceFirst(separator, ""); } public static <T> String join(T[] objs, String separator) { if (objs != null) { return join(Arrays.asList(objs), separator); } else { return ""; } } public static <T> String join(Collection<T> col) { return join(col, ","); } public static <T> String join(T[] col) { return join(col, ","); } }