How to convert a String into an ArrayList?

前端 未结 13 651
囚心锁ツ
囚心锁ツ 2020-11-28 04:32

In my String, I can have an arbitrary number of words which are comma separated. I wanted each word added into an ArrayList. E.g.:

String s = \"a,b,c,d,e,...         


        
13条回答
  •  醉话见心
    2020-11-28 04:47

    If you want to convert a string into a ArrayList try this:

    public ArrayList convertStringToArraylist(String str) {
        ArrayList charList = new ArrayList();      
        for(int i = 0; i

    But i see a string array in your example, so if you wanted to convert a string array into ArrayList use this:

    public static ArrayList convertStringArrayToArraylist(String[] strArr){
        ArrayList stringList = new ArrayList();
        for (String s : strArr) {
            stringList.add(s);
        }
        return stringList;
    }
    

提交回复
热议问题