title: Correct way of adding objects to LinkedList by value
body: <p>I am trying to add many objects to a <code>LinkedList</code>. The first (incorrect way) that I tried was the following:</p>
  
  <p>Person class:</p>
  
  <pre><code>public class Person 
  {
      public double age;
      public String name;
  }
  </code></pre>
  
  <p>(first way) Main file:</p>
  
  <pre><code>import java.util.LinkedList;
  public class Main 
  {
      public static void main(String[] args) 
      {
          LinkedList&lt;Person&gt; myStudents = new LinkedList&lt;Person&gt;();
          Person currPerson = new Person();   
          for(int ix = 0; ix &lt; 10; ix++)
          {
              currPerson.age = ix + 20;
              currPerson.name = "Bob_" + ix;
              myStudents.add(currPerson);
          }
  
          String tempName_1 = myStudents.get(1).name; \\This won't be "Bob_1"
          String tempName_2 = myStudents.get(2).name; \\This won't be "Bob_2"
      }
  }
  </code></pre>
  
  <p>The second way:</p>
  
  <pre><code>import java.util.LinkedList;
  public class Main 
  {
      public static void main(String[] args) 
      {
          LinkedList&lt;Person&gt; myStudents = new LinkedList&lt;Person&gt;();
          for(int ix = 0; ix &lt; 10; ix++)
          {
              Person currPerson = new Person();   
              currPerson.age = ix + 20;
              currPerson.name = "Bob_" + ix;
              myStudents.add(currPerson);
          }
  
          String tempName_1 = myStudents.get(1).name;  \\This will be "Bob_1"
          String tempName_2 = myStudents.get(2).name;  \\This will be "Bob_2"
      }
  }
  </code></pre>
  
  <p>The second way works just fine, but is there a better (or more correct) way to do it? If the second way only uses the addresses of those objects, will that make it risky (as this address might be replaced at later point)? </p>