I ran into a seemingly simple problem that I haven't been able to figure out. Basically, my list holds a number of ints which represent different items, which works fine, but I need to be able to check if the list contains the same integer more than once and then remove them from the list.
if (myList.contains(100)) { // I want to check if the int '100' exists in myList twice
myList.remove(new Integer(100)); // I want to remove the 2 aforementioned duplicate integers
}
Apologies if my explanation wasn't the clearest. Thanks in advance!
EDIT: To clarify, I want the list to contain duplicates but I want to be able to check if the duplicate exists X times and then remove those instances from the list.
i.e.
I might want to add the int 100
7 times, and then later check if it exists twice and then remove 2
instances of it from the list only.