How Best to Compare Two Collections in Java and Act on Them?

前端 未结 8 2192
生来不讨喜
生来不讨喜 2020-12-03 00:41

I have two collections of the same object, Collection oldSet and Collection newSet. The required logic is as follow:

8条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-03 01:36

    For a set that small is generally not worth it to convert from an Array to a HashMap/set. In fact, you're probably best off keeping them in an array and then sorting them by key and iterating over both lists simultaneously to do the comparison.

提交回复
热议问题