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.
Since both number and string are in the same word "item" and stored on the same index, I don't know how I can just get the number. I need the number to test to see if the number already exist
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)
{
stock.add(item);
}