Best way to merge and remove duplicates from multiple lists in Java

前端 未结 3 589
清歌不尽
清歌不尽 2021-02-14 16:00

I have a situation where I will be receiving 2+ ArrayList and I need to be able to merge all the lists and remove any duplicate Widget so

3条回答
  •  你的背包
    2021-02-14 16:23

    I would do it this way

    Set set = new HashSet<>(list1);
    set.addAll(list2);
    List mergeList = new ArrayList<>(set);
    

提交回复
热议问题