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
Map<Entity, Integer>
whereby Entity
is the class being stored in your collection and the Integer
represents the number of times it occurs.Map
- If it exists then decrement the Integer
value by one and perform any action necessary when a match is found. If the Integer
value has reached zero then remove the (Entity, Integer) entry from the map.This algorithm will run in linear time assuming you've implemented an efficient hashCode()
method.