Even if that topic is quite old, I'd like to add something.
If you overwrite equals
for you classes, so it compares your getId
, you can use:
customer = new Customer(id);
customers.get(customers.indexOf(customer));
Of course, you'd have to check for an IndexOutOfBounds
-Exception, which oculd be translated into a null pointer or a custom CustomerNotFoundException
.