-3

A short explanation of what I am trying to achieve:

I have 2 classes, 'Company' and 'Customer'. I create an instance for the company and also for the customer. At this moment I can call the customers object without any problem. When I add it to an ArrayList inside the company object (containing all the customers), I can still reach the customer object on it's own, so without accessing it through the ArrayList.

Why is it that when I remove the object from the list, the object is completely deleted? Is there a way to do this differently so that I, for example can add it to another ArrayList later?

S. Tanghe
  • 97
  • 1
  • 7

1 Answers1

2

As long as you still have a reference to the object it's not destroyed by the Java garbage collector and you can use it w/o any restrictions (e.g., adding to another ArrayList is possible).

MrTux
  • 32,350
  • 30
  • 109
  • 146