title: How to iterate a list inside a list in java?
body: <p>Hi i have two value object classes . </p>
  
  <pre><code>package org.array;
  
  import java.util.List;
  
  
  
  public class Father {
  
      private String name;
      private int age ;
      private List&lt;Children&gt; Childrens;
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
      public int getAge() {
          return age;
      }
      public void setAge(int age) {
          this.age = age;
      }
      public List&lt;Children&gt; getChildrens() {
          return Childrens;
      }
      public void setChildrens(List&lt;Children&gt; childrens) {
          Childrens = childrens;
      }
  
  
  }
  </code></pre>
  
  <p>second is for children</p>
  
  <pre><code>package org.array;
  
  public class Children {
  
      private String name;
      private int age ;
      public String getName() {
          return name;
      }
      public void setName(String name) {
          this.name = name;
      }
      public int getAge() {
          return age;
      }
      public void setAge(int age) {
          this.age = age;
      }
  
  
  }
  </code></pre>
  
  <p>and i want to print there value i nested a list inside a list here i am putting only a single value inside the objects while in real i have many values . so i am nesting list of children inside father list. how can i print or get the value of child and father both. here is my logic.</p>
  
  <pre><code>package org.array;
  
  import java.util.ArrayList;
  import java.util.Iterator;
  import java.util.List;
  
  public class ArrayDemo {
  
      public static void main(String[] args) {
           List &lt;Father&gt; fatherList = new ArrayList&lt;Father&gt;();
          Father father =  new Father();
          father.setName("john");
          father.setAge(25);
          fatherList.add(father);
  
           List &lt;Children&gt; childrens = new ArrayList&lt;Children&gt;();
           Children children = new Children();
          children.setName("david");
          children.setAge(2);
          childrens.add(children);
          father.setChildrens(childrens);
          fatherList.add(father);
  
          Iterator&lt;Father&gt; iterator = fatherList.iterator();
          while (iterator.hasNext()) {
              System.out.println(iterator.toString());
          }
  
  
  
          }
          }
  </code></pre>