I need to have data structure like HashSet
.
- It should not add the same item into the collection
- But instead of adding the same item, it should count times this item was added.
As I understand HashSet
calculates hashCode
at first, if hashCode
is the same it checks equals
method if true than it will not add an item, otherwise item with the same hashCode
but another equals
will be added to the bucket linked list.
What I need to do is just keep only unique objects like Set
does, but using equals
method only, and if objects are equal than increment counter associated with each object.
Is there any such data structure already implemented, or I should create my own ?