How do I transfer an array from one class to another, specifically the int field in the source class array

123 Views Asked by At

I implemented compareTo in my Student class which implements Comparable which has a private int age field. I also have a Classroom class which has a classroom array that takes in Student objects. I have my classroom array and I want to send it's individual int age fields into a new Student array. How would I do that because referencing doesn't work with array indexes in a for loop for example:

 for (int i = 0; i < classroom.getSize(); i++)
        {
            studentArray[i] = classroom[i].getAge();
        }

Assuming my getters are correct and and arrays are declared properly, this declaration doesn't work because it's two different types of objects. What are the alternatives?

0

There are 0 best solutions below