title: How to use scanner to add data dynamically in a collection
body: <p>Help me to scan name and age from the user instead of predefining it in the ArrayList.</p>
  
  <p>I have initialised name and age in the following program help me to scan the name and age from the user and it should compare then it should sort using collection.</p>
  
  <pre><code>public class Control {
      public static void main(String[] args) {
  
          List&lt;Student&gt; studs = new ArrayList&lt;Student&gt;();
          Student stu1 = new Student(22, "Gokul");
          Student stu2 = new Student(12, "Dolby");
          Student stu3 = new Student(24, "Rahul");
          Student stu4 = new Student(56, "Raj");
  
          studs.add(stu1);
          studs.add(stu2);
          studs.add(stu3);
          studs.add(stu4);
  
          Collections.sort(studs,new StudAge());
          for(Student stud : studs) {
              System.out.println(stud);
          }
  
  
      }
  
  }
  </code></pre>