title: How to pull data moving backwards in a java ArrayList
body: <p>I am trying to make it so I can write data to a ArrayList to track random integers and then I will have a previous button that will go back to the last result (This is just testing that code this is not the full code for the project) I am getting an error when trying to take the int arraySize and subtract it by 1 and reprint the data. Any idea why this is happening or how another way to accomplish the task. </p>
  
  <pre><code>int lenth = 10;
  ArrayList&lt;Integer&gt; list = new ArrayList&lt;Integer&gt;();
  int arraySize = list.size();
  Random random = new Random();
  int newRandom = random.nextInt(lenth);
  list.add(newRandom);
  newRandom = random.nextInt(lenth);
  list.add(newRandom);
  System.out.println(list.get(arraySize));
  arraySize--;
  System.out.println(list.get(arraySize));
  </code></pre>
  
  <p>Also here is the error I am getting:</p>
  
  <pre><code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -1
  at java.util.ArrayList.elementData(Unknown Source)
  at java.util.ArrayList.get(Unknown Source)
  at test.C_MainActivity.main(C_MainActivity.java:22)
  </code></pre>