title: Java object added to ArrayList not showing
body: <p>I have two Classes:</p>
  
  <p>Class1 which contains an ArrayList of type Class2</p>
  
  <p>When I try to add a new object as follow:</p>
  
  <pre><code>Class2 object = new Class2();
  Class1Object.getArrayList().add(object);
  </code></pre>
  
  <p>Then it appears that the object has been added when I iterate over getArrayList()</p>
  
  <p>However I have another ArrayList of type class1 and when I iterate over this there object added does not appear?</p>
  
  <p>I thought that since objects are by reference it should be added to the ArrayList of type class1. Can any one explain this please?</p>
  
  <pre><code>public class Subject implements Serializable {
  
  private static final long serialVersionUID = 1L;
  private String subjectName;
  private int hours;
  private int mins;
  private ArrayList&lt;Task&gt; tasks;
  private SimpleDateFormat date;
  
  public Subject(String subjectName){
      this.subjectName = subjectName;
      hours = 0;
      mins = 0;
      tasks = new ArrayList&lt;Task&gt;();
      date = null;
  }
  
  
  public ArrayList&lt;Task&gt; getTasks() {
      return tasks;
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>public class Task implements Serializable {
  
      private static final long serialVersionUID = 2L;
      private String description;
      private boolean isCompleted;
  
      public Task(String description){
          this.description = description;
          isCompleted = false;
      }   
  
  }
  </code></pre>
  
  <p>So then I have:</p>
  
  <pre><code>ArrayList&lt;Subject&gt; subjectsList = new ArrayList&lt;Subject&gt;();
  </code></pre>
  
  <p>And then I want to add a new task to a given subject so I do:</p>
  
  <pre><code>Task task = new Task(description);
  ArrayList&lt;Task&gt; taskList = subject.getTasks();
  taskList.add(task);
  </code></pre>
  
  <p>And when I iterate over <code>subject.getTasks();</code> its there but when I iterate over subjectsList the new task is not there anymore.</p>
  
  <p>Here is the first loop which shows the new task:</p>
  
  <pre><code>for (Task task : subject.getTasks()){
     System.out.println( task.toString() );
  }
  </code></pre>
  
  <p>And the code for iterating over all objects from <code>subjectsList</code></p>
  
  <pre><code>for (Subject s : subjectsList){
   for (Task t : s.getTasks()){
     System.out.println( t.toString() );
      }
  }
  
  
  
  Bundle bundle = getIntent().getExtras();
    if (bundle != null) {
      subject = (Subject) bundle.get("selected_subject");
      subjectsList = (ArrayList&lt;Subject&gt;) bundle.get("subjects_list");
     }
  </code></pre>