Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8865659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:34:09+00:00 2026-06-14T16:34:09+00:00

I have a problem trying to insert a calculated result into an ArrayList of

  • 0

I have a problem trying to insert a calculated result into an ArrayList of Student’s list of results.

It goes like this.

  1. An ArrayList (called FullList) holds a list of Student objects.
  2. A Student object has a name (as a String) and a resultslist (as an ArrayList).
  3. When i receive a Result object, it comes with a name (as a String) and result (as a Integer).
  4. I want to insert this Result object into the Student object’s resultlist.
  5. However, the student names are not defined upfront but deduced upon the receipt of a Results object.
  6. 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.

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.

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?

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 <Student> 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 <Result> resultslist;

   public Student(String name) {
      this.name = name;
      resultslist = new ArrayList <Result> ();
   }

   public void setResult(Result result) {
      this.resultslist.add(result);
   }

   public String getName() {
      return this.name;
   }
}

class StudentResults {

   public static void main (String [] args) {

      ArrayList <Student> FullList = new ArrayList <Student> ();

      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);

   }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:34:10+00:00Added an answer on June 14, 2026 at 4:34 pm

    For each student in the list, you’re inserting a new student if this student doesn’t have the same name as the result to insert:

    for (Student s : fullList) {
         if (s.getName().equalsIgnoreCase(this.name)) { // current student has same name as result
             s.setResult(this);
         }
         else { // current student doesn't have the same name as result
            Student s = new Student(this.name); 
            s.setResult(this);
            fullList.add(s);
         }
    }
    

    The above should be written as:

    Student s = findStudentWithName(fullList, this.name);
    if (s == null) {
        Student s = new Student(this.name); 
        s.setResult(this);
        fullList.add(s);
    }
    else {
        s.setResult(this);
    }
    

    And the findStudentWithName method would look like this:

    private Student findStudentWithName(List<Student> students, String name) {
        for (Student s : students) {
            if (s.getName().equalsIgnoreCase(name)) {
                return s;
            }
        }
        // no student found.
        return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this weird problem when trying to INSERT a row into my mysql
I have a problem using the MySQLdb library. I'm trying to insert values into
I have a problem when trying to insert a new record into a database.
I have encountered a very strange problem when trying to insert multiple Strings into
Gday All, I have a baffling problem whilst trying to insert some chinese characters
I have a problem trying to turn my python code into an executable using
I have a problem when trying to execute this update statement (below) using C#
I have this problem when trying to run hello world program using android SDK.
I'm trying to make a database in android but I have this problem,erase the
I have an annoying problem with mdb2 while trying to insert empty values in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.