Comparing two Collections in Java

前端 未结 7 1480
孤独总比滥情好
孤独总比滥情好 2020-12-15 23:30

I have two Collections in a Java class.The first collection contains previous data, the second contains updated data from the previous collection.

I would like to c

7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-16 00:21

    If not worried about cases like (2,2,3), (2,3,3):

    static  boolean equals(Collection lhs, Collection rhs) {
        return lhs.size( ) == rhs.size( ) && lhs.containsAll(rhs)  && rhs.containsAll(lhs);
    }
    

提交回复
热议问题