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

前端 未结 10 1231
夕颜
夕颜 2021-02-05 06:12

I have a list as below

[url1,url2,url3,url4] 

This list will be based on multiple selection from drop down list of HTML. So list size i.e., lis

10条回答
  •  生来不讨喜
    2021-02-05 06:59

    If you have your elements in an array, you can do something like this:

    import java.util.ArrayList;
    
    class Test1{
        public static void main(String[] args) {
            String[] s = {"url1","url2","url3","url4"};
    
            ArrayList sl = new ArrayList();
            for (int i = 0; i < s.length; i++) {
                sl.add("'" + s[i] + "'"); 
            }
        }
    }
    

提交回复
热议问题