Assigning an array to an ArrayList in Java

后端 未结 4 1457
长发绾君心
长发绾君心 2020-12-01 14:09

Is it possible to assign an array to an ArrayList in Java?

4条回答
  •  庸人自扰
    2020-12-01 14:45

    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);
    

提交回复
热议问题