title: IndexOutOfBoundsException: Index: 7, Size: 7
body: <p>I am trying to figure out why I get this error. My code is as follows:</p>
  
  <pre><code> ArrayList lowestQuant = new ArrayList();
      for (int i = 0; i &lt; aRes1.size(); i++) {
          int var = Math.min(casesQuant.get(i), mainboardQuant.get(i));
          int var2 = Math.min(var, cpuQuant.get(i));
          int var3 = Math.min(var2, ramQuant.get(i));
          int var4 = Math.min(var3, graphicsQuant.get(i));
          lowestQuant.add(var4);
          System.out.println(aRes1.get(i) +" quantity: "+lowestQuant.get(i));
      }
  </code></pre>
  
  <p><code>aRes1</code> is an Array List of computer systems with a length of 8 computer systems.</p>
  
  <p>I need to find the component with the lowest quantity in every computer system, hence the <code>Math.min</code> and all the <code>ArrayList-index</code> look-ups.
  This code should provide the component with the lowest quantity and it does! But somehow it stops before reaching the 8th computer system. It works perfectly with the first <code>7</code>.
  Can anyone tell me what the problem is?
  I've looked a lot of these errors up and tried to set <code>i=1</code> and <code>.size()-1/+1</code> nothing helps. </p>
  
  <p>Thanks in advance!
  Error:</p>
  
  <pre><code> Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 7, Size: 7
              at java.util.ArrayList.RangeCheck(ArrayList.java:547)
              at java.util.ArrayList.get(ArrayList.java:322)
              at databasen.Database.ComputerSystems(Database.java:242)
              at databasen.Database.menuLVL1(Database.java:70)
              at databasen.Database.mainMenu(Database.java:61)
              at databasen.Database.main(Database.java:37)
      Java Result: 1
  </code></pre>
  
  <p>To clarify : All the array lists used are of the same length because they are made from a database. Here are some more code so you can see how the array lists are made ::</p>
  
  <pre><code>ArrayList aRes1 = new ArrayList();
          Statement st = con.createStatement();
          ResultSet rs = st.executeQuery("SELECT catchyname FROM computersystems");
          System.out.printf("Computer sytems:\n");
          while (rs.next()) {
              String answer = rs.getString("catchyname");
              aRes1.add(answer);
          }
  
          // Cases
          ArrayList aRes2 = new ArrayList();
          rs = st.executeQuery("SELECT cases FROM computersystems");
          while (rs.next()) {
              String answer = rs.getString("cases");
              aRes2.add(answer);
          }
          ArrayList&lt;Integer&gt; casesQuant = new ArrayList&lt;Integer&gt;();
          for (int i=0;i&lt;aRes2.size();i++){
              ResultSet rs2 = st.executeQuery("SELECT currentquantity FROM components "
                      + "WHERE name ="+"'"+aRes2.get(i)+"'");
              while (rs2.next()) {
                  int answer2 = rs2.getInt("currentquantity");
                  casesQuant.add(answer2);
              }
          }
  </code></pre>