comparing elements of two arrayList in java

后端 未结 2 672
日久生厌
日久生厌 2020-12-21 03:43

i got two String type arraylist ..one list containing “book1”, “book2”, “book3” and “book4”. And another arrayList contains “book1”, “book2”, “book3”. So, size of first list

2条回答
  •  心在旅途
    2020-12-21 04:03

    You can transform the lists to sets, and then use Set.retainAll method for intersection between the different sets. Once you intersect all sets, you are left with the common elements, and you can transform the resulting set back to a list.

提交回复
热议问题