Accessing methods of objects stored in an ArrayList


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 11 of 11

Thread: Accessing methods of objects stored in an ArrayList

Threaded View

  1. #1
    Join Date
    May 2005
    Posts
    22

    Accessing methods of objects stored in an ArrayList

    Title basically says it all...

    I've got a class and a class nested inside that one, the outer class has an ArrayList object that stores objects of the nested class, and the objects of the nested class have their own ArrayList objects, and need to access/retrieve members of the inner classes' ArrayList objects, but don't know how.

    Now the code, then more clarification.

    Code:
    class ClassList
    {	
    
    	class Student
    	{
    		private String name;
    		private ArrayList grades;
    		private double mean;
       
    		public Student(String n, int g1, int g2, int g3, int g4)
    		{
    			name = n;
    			grades = new ArrayList();
    			grades.add(new Integer(g1));
    			grades.add(new Integer(g2));
    			grades.add(new Integer(g3));
    			grades.add(new Integer(g4));
    		}
    	}
    
    	private ArrayList students;
    	private int studentCount;	
    	private ArrayList testMean;
    	private int testCount;
        	private double classMean;
    
    	public ClassList()
    	{
    		students = new ArrayList();  
    		testMean = new ArrayList();
    		studentCount = 0;
    		testCount = 4;          
    	}
    
    /*
    Assorted blank method stubs that will be filled in with accessing and setting commands, once I figure out how to access the inner array values.
    
    Also a method that reads a .txt file and populates the ClassList arrayList of students and the student ArrayList of grades with values.
    */
    }
    Okay. So each ClassList has an ArrayList of students, and each student has an ArrayList of grades.

    I can access each student object in the classList ArrayList, but I can only retrieve its memory address. I do not know how to access any values of the student objects' ArrayLists (which are stored in the ClassList arrayList and must be accessed from there).

    Final attempt at explaining the problem: How the heck would I retrieve all the grades of a given student knowing only its index in the ClassList ArrayList?

    Any help would be much appreciated. Thanks in advance.
    Last edited by Gengar003; 05-09-2005 at 10:36 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center