I have an ArrayList and I need to convert it to one String.
Each value in the String will be inside mark and will be separated by comma something like this:
ArrayList list = [a,b,c]
String s = " ’a’,’b’,’c’ ";
I am looking for efficient solution .
You can follow these steps: –
Create an empty
StringBuilderinstanceIterate over your
listFor each element, append the representation of each element to your StringBuilder instance
Now, since there would be a last comma left, you need to remove that. You can use
StringBuilder.replace()to remove the last character.You can take a look at documentation of
StringBuilderto know more about various methods you can use.