user2515189 user2515189 - 1 year ago 109
Java Question

How to add or insert ' (single quotes) for every string in a list in which strings are seperated by commas using Java

I have a list as below


This list will be based on multiple selection from drop down list of HTML. So list size i.e., list elements change dynamically. My problem is I am unable to get the logic for getting single quotes to the strings.
I want the above string list to be displayed as


That is single quotes (
) for each string and commas (
) should not be eliminated. Please help me how to achieve this using Java.

Answer Source

1) Iterate the list (for/while)

2) For each elements of list append ' ',.(Hint: use append() on StringBuilder

3) Truncate /substring the list to remove the last , added (Hint: use substring on String class)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download