Merging two arrayLists into a new arrayList, with no duplicates and in order, in Java

前端 未结 14 1511
予麋鹿
予麋鹿 2020-11-28 11:50

I am trying to \"combine\" two arrayLists, producing a new arrayList that contains all the numbers in the two combined arrayLists, but without any duplicate elements and the

14条回答
  •  迷失自我
    2020-11-28 12:04

    Add ArrayList1, ArrayList2 and produce a Single arraylist ArrayList3. Now convert it into

    Set Unique_set = new HashSet(Arraylist3);
    

    in the unique set you will get the unique elements.
    Note

    ArrayList allows to duplicate values. Set doesn't allow the values to duplicate. Hope your problem solves.

提交回复
热议问题