Method to add element to arraylist avoid adding the same id number twice
I have a method which add element to an arraylist
My task is to Modify the addProduct method so that a new product
cannot be added to the product list with the same ID
as an existing one.
I have tryed to use an if test to see if there are some id number allready in the list, but it wont work.
Any suggestion on how I should do this?
The way I add to the arraylist is like this below:
(new Product(132, "Clock Radio"))
public void addProduct(Product item)