title: How to delete an object from its pointer?
body: <p>I have an object that I added to a few different ArrayLists. I wanna avoid changing every list, so I'm trying to change the pointer so all the lists change. But I can't get that to work if I want to set the object to null. For example:</p>
  
  <pre><code>ArrayList&lt;Point&gt; list1 = new ArrayList&lt;Point&gt;();
  ArrayList&lt;Point&gt; list2 = new ArrayList&lt;Point&gt;();
  Point a = new Point(2, 3);
  list1.add(a); list2.add(a);
  </code></pre>
  
  <p>At this point, both lists have an item pointing at the same object. With the value "2, 3". If I change the value of the object. Then both lists changes:</p>
  
  <pre><code>a.set(5,5);
  </code></pre>
  
  <p>Now both lists have an item of value "5, 5". But if I try to set the value to null.</p>
  
  <pre><code>a = null;
  </code></pre>
  
  <p>Now the <code>a</code> is set to null, but the object both lists is still "5, 5" and not null like I wanted. I even tried to add a method to the <code>Point</code> class to set itself to null. But I couldn't get that to work either. What could I do to delete the object on all lists by changing only the pointer?</p>