How to convert a String into an ArrayList?

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

    If you are importing or you have an array (of type string) in your code and you have to convert it into arraylist (offcourse string) then use of collections is better. like this:

    String array1[] = getIntent().getExtras().getStringArray("key1"); or String array1[] = ... then
    
    List allEds = new ArrayList(); Collections.addAll(allEds, array1);
    

提交回复
热议问题