I have a class (cars) that has an int ID instance variable.
The ID does not necessarily have to be unique - it is more of a category ID.
If the ID exists I add the object to an array list within that category if the ID does not exist I create a new category with that ID
Before I create an instance of this class I want to check that there isn't already an instance variable with that ID.
The only way I can think of doing this right now is having a static arraylist of all the cars within the class cars. I then search through the array list through each car and compare IDs to see if there is an ID that already matches. if not - I create the the new car instance with the new ID.
Surely there is a better way of doing this?