title: How to add to Arraylist and show it in Java?
body: <p>I am a noob in Java so far and I am having issues with this program. In this program, users can add student info and see the info. However my add function (I think does not work so I am not using it properly I guess). I realized that my error is that the index is out of boundaries, but I am not using set, I am using add so I guess it should increase the length of the arraylist isn't that right? Anyways, this is the code:</p>
  <pre><code>public class Student {
  
  Scanner scan = new Scanner(System.in);
  String name_s, surname_s;
  int age_s, number_s;
  int choice;
  int index;
  
  public void Studentt() {
      
      ArrayList&lt;String&gt; name = new ArrayList&lt;String&gt;();
      ArrayList&lt;String&gt; surname = new ArrayList&lt;String&gt;();
      ArrayList&lt;Integer&gt; age = new ArrayList&lt;Integer&gt;();
      ArrayList&lt;Integer&gt; number = new ArrayList&lt;Integer&gt;();
  
      System.out.println(&quot;To add student:1\nTo see student:2&quot;);
      this.choice = Integer.parseInt(scan.nextLine());
  
      if (choice == 1) {
          System.out.println(&quot;Name:&quot;);
          this.name_s = scan.nextLine();
          name.add(name_s);
          System.out.println(&quot;Surname:&quot;);
          this.surname_s = scan.nextLine();
          surname.add(surname_s);
          System.out.println(&quot;Age:&quot;);
          this.age_s = Integer.parseInt(scan.nextLine());
          age.add(age_s);
          System.out.println(&quot;Number&quot;);
          this.number_s = Integer.parseInt(scan.nextLine());
          number.add(number_s);
          end();
      } else if (choice == 2) {
  
          System.out.println(&quot;Index of the student you want to see:&quot;);
          this.index = Integer.parseInt(scan.nextLine());
          System.out.println(name.get(index));
          System.out.println(surname.get(index));
          System.out.println(age.get(index));
          System.out.println(number.get(index));
          System.out.println(&quot;Done.&quot;);
          end();
      } else {
          System.out.println(&quot;Wrong choice.&quot;);
          Studentt();
  
      }
  
  }
  
  public void end() {
      try(Scanner scan = new Scanner(System.in)){
          int menu;
          System.out.println(&quot;To repeat:1 \nExit:2&quot;);
          menu = Integer.parseInt(scan.nextLine());
          if (menu == 1) {
              Studentt();
          } else if (menu == 2) {
              System.out.println(&quot;Done.&quot;);
          } else {
              System.out.println(&quot;Wrong choice.&quot;);
              end();
          }
      }
  
  }
  </code></pre>
  <p>and this is the output:</p>
  <pre><code>Exception in thread &quot;main&quot; java.lang.IndexOutOfBoundsException: Index 1 out of bounds for length 0
  </code></pre>