Java Compare Two Lists

后端 未结 10 585
情深已故
情深已故 2020-11-22 13:25

I have two lists ( not java lists, you can say two columns)

For example

**List 1**            **Lists 2**
  milan                 hafil
  dingo               


        
10条回答
  •  攒了一身酷
    2020-11-22 13:32

    Of all the approaches, I find using org.apache.commons.collections.CollectionUtils#isEqualCollection is the best approach. Here are the reasons -

    • I don't have to declare any additional list/set myself
    • I am not mutating the input lists
    • It's very efficient. It checks the equality in O(N) complexity.

    If it's not possible to have apache.commons.collections as a dependency, I would recommend to implement the algorithm it follows to check equality of the list because of it's efficiency.

提交回复
热议问题