How to concat two ArrayLists?

后端 未结 7 1300
伪装坚强ぢ
伪装坚强ぢ 2020-12-13 23:29

I have two ArrayLists of equal size. List 1 consists of 10 names and list 2 consists of their phone numbers.

I want to concat the names and number into

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-14 00:14

    add one ArrayList to second ArrayList as:

    Arraylist1.addAll(Arraylist2);
    

    EDIT : if you want to Create new ArrayList from two existing ArrayList then do as:

    ArrayList arraylist3=new ArrayList();
    
    arraylist3.addAll(Arraylist1); // add first arraylist
    
    arraylist3.addAll(Arraylist2); // add Second arraylist
    

提交回复
热议问题