I want to store a set of integers with duplicates allowed, for example 1, 5, 3, 3, 4, 6
.
If I use a HashSet
, the duplicates are lost.
A List
feels wrong as the items have no order implied. I need to be able to delete items from the middle quickly which rules out ArrayList
. LinkedList
still implies the items have some order which I don't like.
Is there another data structure I should use for this? Or should I tell HashSet
to compare Integer
based on reference equality?
I know I can work around this in a few ways but I'm more interested in the most 'correct' solution.