I have got a list of string and now I want to take the list into a String with comma(,) separation is concat method the only way or there is some easy and good way
StringBuilder s = null;
List<String> listObjs (5 strings in it)
for(String listObj : listObjs)
s.append(listObj);
s.append(",");
EDIT: guys at SO rocks....slew of answers in seconds..wow!!
You can do
StringBuilder sb = new StringBuilder();
String sep = "";
for (String s : listObjs) {
sb.append(sep).append(s);
sep = ", ";
}
System.out.println(sb);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With