Java tutorial
//package com.java2s; import java.util.*; public class Main { /** * Join a bunch of objects into a string delimited by the separator * * @param sep * @param c * @return */ public static String join(final String sep, final Collection<? extends Object> c) { if (c == null) { return null; } if (c.size() == 1) { return String.valueOf(c.iterator().next()); } if (c.size() == 0) { return ""; } final StringBuilder sb = new StringBuilder(); String s = ""; for (final Object o : c) { sb.append(s).append(String.valueOf(o)); s = sep; } return sb.toString(); } /** * Join a bunch of objects into a string delimited by the separator * * @param sep * @param ol * @return */ public static String join(final String sep, final Object... ol) { if (ol == null || ol.length == 0) { return ""; } if (ol.length == 1) { return String.valueOf(ol[0]); } final StringBuilder sb = new StringBuilder(); String s = ""; for (final Object o : ol) { sb.append(s).append(String.valueOf(o)); s = sep; } return sb.toString(); } /** * @param sep * @param sl * @return */ public static String join(final String sep, final String... sl) { return join(sep, (Object[]) sl); } public static int size(Collection<?> c) { return (c == null) ? 0 : c.size(); } }