java - Access all elements of an arraylist from an object which is stored in an arraylist (2 Dimentional) -
so have several "student" objects in arraylist, each student has arraylist of courses. how access of courses particular student? in advance.
scanner studentcourse = new scanner(system.in); int j = 0; system.out.println("which students course(s) want view?"); for(student l:liststudent) { system.out.print(j+1 + ")"); system.out.println(l); j++; } int course = studentcourse.nextint(); int k = s.listcourse.size();//need size of correct array list int l = 0; while( l < k ){ system.out.println(s.listcourse.get(0));//need print of elements in correct array list } break; public class student { string studentfirstname, studentlastname; int studentid; double studentgpa; arraylist<course> listcourse = new arraylist<>(); }
your question understandable, not code.
student student = studentlist.get(indexposition); //arraylist gives flexibility , that's advantage of arraylist on other lists if(student.getcourseslist()!=null && !student.getcourseslist().isempty()){ for(course course: student.getcourseslist()){ system.out.println(course); } }
Comments
Post a Comment