This is a simple java coding question.
I have a List of String
[Say "hello" "how" "are" "you?"
]. I need to insert a delimiter [-
] between each element of the list so that my output is hello-how-are-you?
One simple way of doing this is as below:
private static String addDelim(List<String> a)
{
String s = "";
for(int i=0; i<a.size(); i++)
{
if(i != 0) // don't add if first element
{
s += "-";
}
s += a.get(i);
}
return s;
}
Is there any elegant way of doing this?