title: How to use loop to list instances content?
body: <p>I am new to android development.  In the following, I know how to loop through the school list.  However, I don't know how to use loop to display the the students in school, because each school instances is manually created. Is there a way I can display each school and its students using loop?  Thanks.</p>
  
  <p>My data is as followed:</p>
  
  <pre><code>school id: A1, "Point Grey"
  Student name: "Kent", "Age": 43
  Student name: "Jane", "Age": 18
  Student name: "Winnie", "Age": 19 
  
  school id: B1, "Prince of Wales"
  Student name: "Steven", "Age": 11
  Student name: "Michelle", "Age": 30
  Student name: "Ronald", "Age": 20
  </code></pre>
  
  <p>My Directory is as followed:</p>
  
  <pre><code>public class DIRECTORY {
     private Map&lt;String, SCHOOL&gt; schools = new HashMap&lt;String, SCHOOL&gt;();
  
  
      public void setSchools(Map&lt;String, SCHOOL&gt; schoolsMap) {
      this.schools =  schoolsMap;
      }
  
   public Map&lt;String, SCHOOL&gt; getSchools() {return this.schools;}
  
  
   public void addSchool(String schoolId, String schoolName) {
       SCHOOL school = new SCHOOL();
       school.setSchoolId(schoolId);
       school.setSchoolName(schoolName);
       schools.put(schoolId,school);
  
     }
  
      public SCHOOL getSchoolById(String schoolId) {
          schools.get(schoolId);
      }
  
     }
  </code></pre>
  
  <p>My School class as followed:</p>
  
  <pre><code>public class SCHOOL {
  private String schoolId;
  private String schoolName;
  private List&lt;STUDENT&gt; students = new ArrayList&lt;&gt;();
  
  //getter and setter for schoolid and school name 
  public void setStudents(STUDENT students) {
      this.students = (List&lt;STUDENT&gt;) students;
  }
  public List&lt;STUDENT&gt; getStudents() {return this.students;}
  public void addStudent(String names, String age) {
      STUDENT student = new STUDENT();
      student.setNames(names);
      student.setAge(age);
      students.add(student);
  }
  </code></pre>
  
  <p>My student class as followed:</p>
  
  <pre><code>public class STUDENT {
  private String names;
  private String age;
  //getter and setter for name and age
  
  }
  </code></pre>
  
  <p>My data is as followed:</p>
  
  <pre><code>private static DIRECTORY createDummySchool(){
  
      DIRECTORY directory = new DIRECTORY();
      directory.addSchool("A1", "Point Grey");
      directory.addSchool("B1", "Prince of Wales");
  
      SCHOOL schoolA1 = directory.getSchoolById("A1");
  
      schoolA1.addStudent("kent", "43");
      schoolA1.addStudent("Winnie", "19");
      schoolA1.addStudent("Jane", "18");
  
      SCHOOL schoolB1 = directory.getSchoolById("B1");
      schoolB1.addStudent("Steven", "11");
      schoolB1.addStudent("Michelle", "30");
      schoolB1.addStudent("Ronald", "20");
  
      return directory;
  }
  </code></pre>
  
  <p>My Directory List as followed:</p>
  
  <pre><code>public String outputDirectorylist(List&lt;DIRECTORY&gt; directorylist) {
      StringBuilder sb = new StringBuilder();
      for (DIRECTORY directory:directorylist) {
          sb.append(school.getSchoolId());
          sb.append(",");
          sb.append(school.getSchoolName());
          sb.append(";");
      }
  
      return String.valueOf(sb);
  
  }
  </code></pre>
  
  <p>My Main class is as followed:</p>
  
  <pre><code> .....
   DIRECTORY directorylist = directory.getSchools();
   // How to loop the student in each school?
   Log.d(tag, outputSchool(directorylist));
   .....
  </code></pre>