How can I get a List<Student> data in School list?
List<School> schools = new ArrayList<School>();
School school_aaa = new School();
school_aaa.setName( "aaa" );
Student student_aaa_001 = new Student();
student_aaa_001.setName( "aaa_001" );
student_aaa_001.setAge( 17 );
student_aaa_001.setId( 21345678 );
Student student_aaa_002 = new Student();
student_aaa_002.setName( "aaa_002" );
student_aaa_002.setAge( 13 );
student_aaa_002.setId( 6789876 );
List<Student> students = new ArrayList<Students>();
students.add( student_aaa_001 );
students.add( student_aaa_002 );
school_aaa.setStudents( students );
schools.add("aaa");
I only have school name. But it couldn't use indexOf method. because that's only works same object.
that means I need to get School object not school name.
how do I find School object.
here are DataTypes.
Student.java

School.java

It seems like you are trying to find a specific school in the list of schools. If this is not what you are trying to do, please let me know.
Here's how I would do it:
public School findSchool(String schoolName)
{
// Goes through the List of schools.
for (School i : schools)
{
if (i.getName.equals(schoolname))
{
return i;
}
}
return null;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With