I believe blogs are a great platform for learning and sharing. I urge you to reply to this post with which method you prefer and if possible, a line or two explaining why.
Method 1: Good Plain Ol' Java
StringBuilder builder = new StringBuilder();
for(Object o : listOfObjects) { //listOfObjects is not null and not empty
builder.append(o.toString());
builder.append(",");
}
builder.deleteChatAt(builder.length()-1);
return builder.toString();
Method 2: Use Google Guava Libraries
return Joiner.on(",").join(listOfObjects);
My preference :
I do see the benefit of Method 2 in reduced number of lines and similarity to many dynamic programming languages like Python. However, I feel it lacks flexibility when compared to Method 1, where I can choose what I append to the resulting String.
What say you?
Method 1: Good Plain Ol' Java
StringBuilder builder = new StringBuilder();
for(Object o : listOfObjects) { //listOfObjects is not null and not empty
builder.append(o.toString());
builder.append(",");
}
builder.deleteChatAt(builder.length()-1);
return builder.toString();
Method 2: Use Google Guava Libraries
return Joiner.on(",").join(listOfObjects);
My preference :
I do see the benefit of Method 2 in reduced number of lines and similarity to many dynamic programming languages like Python. However, I feel it lacks flexibility when compared to Method 1, where I can choose what I append to the resulting String.
What say you?