title: adding a full list of objects to every object in the list in JAVA
body: <p>Hi I have 2 classes in Java, <code>Gossip</code> and <code>Node</code>, I want that <code>Gossip</code> will hold a list of all the objects of <code>Node</code> class and I want that each <code>Node</code> object will also have that list. I tried to write it in the following way:</p>
  
  <pre><code>public class Node {
  
      private Boolean val = null;
      private LinkedList&lt;Node&gt; list;
      static  Random rand = new Random(); 
  
      public Node(LinkedList&lt;Node&gt; list) {
          this.list=list; 
      }
      ... the rest of Node functions ...
  }
  </code></pre>
  
  <p>and in the <code>Gossip</code> contractor:</p>
  
  <pre><code>public class Gossip {
  
      private int count;
      private int n;
  
      private LinkedList&lt;Node&gt; list;
  
      public Gossip (int n) {
          this.count = 0;
          this.n = n;
          list = new LinkedList&lt;Node&gt;();
          for (int i=0; i&lt;n; i++){
              list.add(new Node(list));
          }
      }
      ... the rest of Gossip functions ...
  }
  </code></pre>
  
  <p>Since I'm used to <code>C++</code> I am not sure how it works here and whether this will work like a pointer and each <code>Node</code> will have a full list or will each <code>Node</code> will only have a list with the <code>Node</code>s created before it and itself. Also, I don't need to change the list on the program, just to read from it, but it's interesting, will a change that one <code>Node</code> does in the list will affect all other <code>Node</code>s's lists?</p>