I have one problem when appending List values as String. I will be getting 1 or more than 1 value into the list. Then I need to append these string as one string and use a separator , for each string. But at the end also the comma is getting added. How Can I remove this at the end of the string dynamically. Here is my code:
cntList = parseXml(metadata.xml);
if (cntList.size() != 0) {
// entryCountryMap.put(id, country);
System.out.println("Size is ---->" + cntList.size());
StringBuilder sb = new StringBuilder();
if (cntList.size() >= 2) {
for (String s : cntList) {
sb.append(s);
sb.append(",");
}
}
System.out.println("StringBuilder ----->" + sb.toString());
}
And my output is like this:
StringBuilder ----->All Countries,US - United States,
Please help me resolving this. Thanks - Raji