title: How to insert Java object into an ArrayList?
body: <p>I have a problem trying to insert a calculated result into an ArrayList of Student's list of results.</p>
  
  <p>It goes like this.</p>
  
  <ol>
  <li>An ArrayList (called FullList) holds a list of Student objects.</li>
  <li>A Student object has a name (as a String) and a resultslist (as an ArrayList).</li>
  <li>When i receive a Result object, it comes with a name (as a String) and result (as a Integer).</li>
  <li>I want to insert this Result object into the Student object's resultlist.</li>
  <li>However, the student names are not defined upfront but deduced upon the receipt of a Results object.</li>
  <li>That is to say, if there is no Student object in FullList, the Result object will trigger the creation of a Student object and insert itself into the Student object's resultslist.
  Then the created Student object will be inserted into FullList.</li>
  </ol>
  
  <p>I have written the code below but I'm getting multiple insertions of the same tag into FullList instead of insertion of multiple results into each tag.</p>
  
  <p>Q1: I can't figure out what's wrong! Need a mind prick from the Gurus!
  Q2: I will be using the following code for up to 90,000 students. Is this a feasible way of housing student results?</p>
  
  <pre><code>class Result {
     String name;
     int result;
  
     public Result(String name, int result) {
        this.name = name;
        this.result = result;
     }
  
     /* start - Getting hungup over this method
      *         Something is wrong here and i don't know what it is
      */
     public void setResult(ArrayList &lt;Student&gt; fullList) {
  
        for (Student s : fullList) {
           if (s.getName().equalsIgnoreCase(this.name)) {
              s.setResult(this);
           }
           else {         /* enters here if Student does not exist in fullList */
              Student s = new Student(this.name); /* create new student */
              s.setResult(this);                  /* insert result into Student's resultslist */
              fullList.add(s);                    /* add Student into fullList */
           }
        }
     }
     /* end */
  
     public String getName() {
        return this.name;
     }
  }
  
  class Student {
     String name;
     ArrayList &lt;Result&gt; resultslist;
  
     public Student(String name) {
        this.name = name;
        resultslist = new ArrayList &lt;Result&gt; ();
     }
  
     public void setResult(Result result) {
        this.resultslist.add(result);
     }
  
     public String getName() {
        return this.name;
     }
  }
  
  class StudentResults {
  
     public static void main (String [] args) {
  
        ArrayList &lt;Student&gt; FullList = new ArrayList &lt;Student&gt; ();
  
        Result r1 = new Result("John", 12);
        Result r2 = new Result("Jamie", 99);
        Result r3 = new Result("John", 69);
        Result r4 = new Result("Jacque", 56);
        Result r5 = new Result("Jacque", 100);
        Result r6 = new Result("Jamie", 100);
  
        r1.setResult(FullList);
        r2.setResult(FullList);
        r3.setResult(FullList);
        r4.setResult(FullList);
        r5.setResult(FullList);
        r6.setResult(FullList);
  
     }
  }
  </code></pre>