Remove all objects in an arraylist that exist in another arraylist

前端 未结 4 1518
梦谈多话
梦谈多话 2020-12-17 07:25

I\'m trying to read in from two files and store them in two separate arraylists. The files consist of words which are either alone on a line or multiple words separated by c

4条回答
  •  余生分开走
    2020-12-17 08:22

    You can use the removeAll method to remove the items of one list from another list.

    To obtain the duplicates you can use the retainAll method, though your approach with the set is also good (and probably more efficient)

提交回复
热议问题