2009-07-03 08:58:05 -04:00
|
|
|
|
|
|
|
package net.sourceforge.tuned;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Iterator;
|
|
|
|
|
|
|
|
|
|
|
|
public final class StringUtilities {
|
|
|
|
|
|
|
|
public static String join(Object[] values, CharSequence delimiter) {
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
for (int i = 0; i < values.length; i++) {
|
|
|
|
sb.append(values[i]);
|
|
|
|
|
|
|
|
if (i < values.length - 1) {
|
|
|
|
sb.append(delimiter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-07-24 16:28:25 -04:00
|
|
|
public static String join(Iterable<?> values, CharSequence delimiter) {
|
2009-07-03 08:58:05 -04:00
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
for (Iterator<?> iterator = values.iterator(); iterator.hasNext();) {
|
|
|
|
sb.append(iterator.next());
|
|
|
|
|
|
|
|
if (iterator.hasNext()) {
|
2009-07-24 16:28:25 -04:00
|
|
|
sb.append(delimiter);
|
2009-07-03 08:58:05 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return sb.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dummy constructor to prevent instantiation.
|
|
|
|
*/
|
|
|
|
private StringUtilities() {
|
|
|
|
throw new UnsupportedOperationException();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|