String combine(String[] s, String glue)
{
int k = s.length;
if ( k == 0 )
{
return null;
}
StringBuilder out = new StringBuilder();
out.append( s[0] );
for ( int x=1; x < k; ++x )
{
out.append(glue).append(s[x]);
}
return out.toString();
}
public static String join(String s, Object... a) {
StringBuilder o = new StringBuilder();
for (Iterator<Object> i = Arrays.asList(a).iterator(); i.hasNext();)
o.append(i.next()).append(i.hasNext() ? s : "");
return o.toString();
}
递归:
public static String join(String s, Object... a) {
return a.length == 0 ? "" : a[0] + (a.length == 1 ? "" : s + join(s, Arrays.copyOfRange(a, 1, a.length)));
}