title: Java ArrayList, I don't know what an IndexOutOfBoundsException is
body: <p>This is the code and add numbers and remove if the par1 or par2 is even.
  and give me this <a href="https://i.stack.imgur.com/RUxPW.png" rel="nofollow noreferrer">error</a></p>
  <pre><code>ArrayList&lt;Integer&gt; s;
  Scanner sc=new Scanner(System.in);
  Scanner sm=new Scanner(System.in);
  s= new ArrayList&lt;&gt;();
  int dorinta=sc.nextInt();
  if(dorinta ==1)
      {int numere =sm.nextInt();
      for(int i=0;i&lt;numere;i++)
      {
          Integer x=sc.nextInt();
          s.add(x);
      }
  }
  Random random = new Random();
  while(s.size()!=0)
  {int i=s.size();
      int par1 = random.nextInt(20);
  
      System.out.println(par1);
  
      if(par1 % 2==0)
      {
         s.remove(s.size());
      }
      int par2= random.nextInt(20);
  
      Integer j= random.nextInt(15);
  
      System.out.println(par2);
      if(par2 %2 ==0)
      {
          s.add(j);
      }
  
      System.out.println(s);
  }
  </code></pre>