title: Why do I get an "index out of bounds" exception for my vertical product summation program?
body: <p>So I'm trying to build a program to take a list of integers (specifically 400) that represents a 20x20 matrix and find the greatest product of four vertically consecutive integers in this list.  In this situation, the numbers at the indexes 0, 20, 40, &amp; 60 would be vertically consecutive numbers.  For some reason, the java console is spitting out the following error: </p>
  
  <blockquote>
    <p>Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 418 out of bounds for length 400
       at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
       at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
       at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
       at java.base/java.util.Objects.checkIndex(Objects.java:372)
       at java.base/java.util.ArrayList.get(ArrayList.java:458)
       at Main.getDigitsVertical(Main.java:101)
       at Main.productListVertical(Main.java:59)
       at Main.main(Main.java:10)
    exit status 1</p>
  </blockquote>
  
  <p>Here is my code:</p>
  
  <pre><code>import java.math.BigInteger;
  import java.io.*; 
  import java.util.*; 
  
  class Main {
    public static void main(String[] args) {
  
      String data = "08022297381500400075040507785212507791084949994017811857608717409843694804566200814931735579142993714067538830034913366552709523046011426924685601325671370236912231167151676389419236542240402866331380244732609903450244753353783684203517125032988128642367102638406759547066183864706726206802621220956394396308409166499421245558056673992697177878968314883489637221362309750076442045351400613397343133957817532822753167159403800462161409535692163905429635314755588824001754243629855786560048357189070544443744602158515417581980816805944769287392138652177704895540045208839735991607975732162626793327986688366887576220720346336746551232639353690442167338253911249472180846293240627636206936417230238834629969826759857404361620733529783190017431497148868116235705540170547183515469169233486143520189196748";  
      //System.out.println(greatestProduct(productList(parseListOfStrings(chopString(data)), 0, 3)));
      System.out.println(greatestProduct(productListVertical(parseListOfStrings(chopString(data)), 0, 3, 20)));
  
    }
  
    public static ArrayList&lt;String&gt; chopString(String s) {
        String choppyBoi = new String(s);
        ArrayList&lt;String&gt; result = new ArrayList&lt;&gt;();
        while (choppyBoi.length() &gt; 1) {
          result.add(choppyBoi.substring(0,2));
          choppyBoi = choppyBoi.substring(2);
        }
        //result.add(choppyBoi);
        return result;
      }
  
      public static ArrayList&lt;Integer&gt; parseListOfStrings(ArrayList&lt;String&gt; s) {
        ArrayList&lt;Integer&gt; result = new ArrayList&lt;&gt;();
        for (String strung : s) {
          result.add(Integer.parseInt(strung));
        }
        return result;
      }
      public static int greatestProduct(ArrayList&lt;Integer&gt; list){
        int biggestNum = 1;
        for(int i = 0; i &lt; list.size(); i++){
  
          if(list.get(i) &gt; biggestNum){
            biggestNum = list.get(i);
          }
        }
        return biggestNum;
  
      }
  
      public static ArrayList&lt;Integer&gt; productListVertical(ArrayList&lt;Integer&gt; myLi, int min, int max, int rowLen){
  
        ArrayList&lt;Integer&gt; runningList = new   ArrayList&lt;Integer&gt;();
        for(int i = min; i &lt; myLi.size() - max; i++){
  
          runningList.add(productSummation(getDigitsVertical(myLi, min  + i, max + i, rowLen)));
  
        }
        return runningList;
  
    }
  
      public static int productSummation(ArrayList&lt;Integer&gt; myList){
  
      int runningResult = 1;
      for(int i = 0; i &lt; myList.size(); i++){
  
        runningResult *= myList.get(i);
  
      }
      return runningResult;
  
    }
  
    public static ArrayList&lt;Integer&gt; getDigitsVertical(ArrayList&lt;Integer&gt; myList, int min, int max, int rowLen){
  
      ArrayList&lt;Integer&gt; runningResult = new ArrayList&lt;Integer&gt;();
      int c = 1;
  
      for(int i = min; i &lt;= max * rowLen; i+= rowLen){
  
        c = myList.get(i);
        runningResult.add(c);
        if(min == (myList.size() - max)){
        return runningResult;
      }
  
      }
      return runningResult;
  
    }
  
  }
  </code></pre>
  
  <p>Why do I get this error and how can I fix it?</p>