I have set up a test that:
- retrieves data concerning several court cases: each court case is stored in a CourtCase object
- a set of CourtCase objects is then stored in a Map
- I retrieve these data twice (from two different sources) so I end up with two Maps
The data within the objects should be the same between the Maps, but the order of the objects within the Maps may not be:
Map1:
A, case1 – B, case2 – C, case3
Map2:
B, case2 – A, case1 – C, case3
How can I best compare these two Maps?
Map#equalsdoes not care about the order. As long as your 2 maps contain the same mapping it will return true.Map#equalsusesSet#equalsmethod, applied to the entry set.Set#equalscontract:Note: this assumes that your
CourtCaseobjects have properequalsandhashcodemethods to be compared.