Posted: 28 January 2013 in Uncategorized

I get annoyed having to import apache commons everytime I want to do a simple join when all I need is a simeple method that does this:

private String join(String[] array, String separator){
StringBuilder toReturn=new StringBuilder("");
for (String element : array) {
if (!"".equals(toReturn.toString())){
toReturn.append(separator);
}
toReturn.append(element);
}
return toReturn.toString();
}

Advertisements
Comments
  1. it should really be part of the Arrays utility methods, in my opinion.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s