I am attempting to add a comma separator to the String representation of a Java ArrayList but nothing seems to work, I am obviously missing something simple.
Sadly old Java 6 (running in a JSP):
ArrayList zones= new ArrayList();
zones.add(pageContext.getAttribute("zone"));
for(int i=0; i<zones.size(); i++)
out.println(zones.get(i));
// output is CellA116 CellA116 CellA116 Reception Reception CellA11
StringBuffer stringBuffer = new StringBuffer();
for(int i=0; i<zones.size(); i++)
{
stringBuffer.append(zones.get(i));
stringBuffer.append(",");
}
out.println(stringBuffer.toString());
// output is CellA116,CellA116,CellA116,Reception,Reception,CellA11, (commas)
%>
</tr>
</c:forEach>
syntax wont work here (outside of loop)
out.println(stringBuffer.substring(0, stringBuffer.length() - 1));
I need to remove the final comma (as I eventually want to use the array in chart.js), appreciate any thoughts.