且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

比较两个列表并从中删除重复项

更新时间:2023-02-22 12:35:01

您可以使用 TreeSet 与自定义 Comparator:

  • 使用 Comparator 构建 TreeSet,实现您想要的自定义逻辑
  • 使用 set.addAll(bookList)
  • construct the TreeSet with a Comparator implementing the custom logic you want
  • use set.addAll(bookList)

现在 Set 只包含独特的书籍.

Now the Set contains only unique books.