Adding to an ArrayList Java

后端 未结 7 1418
终归单人心
终归单人心 2020-11-28 12:24

I am a beginner to java, and need some help.

I am trying to convert an Abstract Data type Foo which is an associated list to an Arraylist of the strings B. How do yo

7条回答
  •  攒了一身酷
    2020-11-28 12:54

    If you have an arraylist of String called 'foo', you can easily append (add) it to another ArrayList, 'list', using the following method:

    ArrayList list = new ArrayList();
    list.addAll(foo);
    

    that way you don't even need to loop through anything.

提交回复
热议问题