How to convert a String into an ArrayList?

前端 未结 13 644
囚心锁ツ
囚心锁ツ 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:49

    Ok i'm going to extend on the answers here since a lot of the people who come here want to split the string by a whitespace. This is how it's done:

    List List = new ArrayList(Arrays.asList(s.split("\\s+")));
    

提交回复
热议问题