How to convert an ArrayList
to a String
in Java?
The toString
method returns it as [a,b,c]
string - I wa
You can iterate through the list and create the string.
String getStringRepresentation(ArrayList list)
{
StringBuilder builder = new StringBuilder(list.size());
for(Character ch: list)
{
builder.append(ch);
}
return builder.toString();
}
As an aside, toString()
returns a human-readable format of the ArrayList's contents. It is not worth the time to filter out the unnecessary characters from it. It's implementation could change tomorrow, and you will have to rewrite your filtering code.