Wednesday, October 28, 2009

My Favorite Join Function

My favorite implementation of a join function (in Java):

public static <T> String join(T[] array, String delimiter)
{
if (array.length == 0)
return "";
StringBuilder builder = new StringBuilder();
builder.append(array[0]);
for (int i = 1; i < array.length; i++)
builder.append(delimiter).append(array[i]);
return builder.toString();
}

No comments: