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, & 60 would be vertically consecutive numbers. For some reason, the java console is spitting out the following error:
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
Here is my 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<String> chopString(String s) {
      String choppyBoi = new String(s);
      ArrayList<String> result = new ArrayList<>();
      while (choppyBoi.length() > 1) {
        result.add(choppyBoi.substring(0,2));
        choppyBoi = choppyBoi.substring(2);
      }
      //result.add(choppyBoi);
      return result;
    }
    public static ArrayList<Integer> parseListOfStrings(ArrayList<String> s) {
      ArrayList<Integer> result = new ArrayList<>();
      for (String strung : s) {
        result.add(Integer.parseInt(strung));
      }
      return result;
    }
    public static int greatestProduct(ArrayList<Integer> list){
      int biggestNum = 1;
      for(int i = 0; i < list.size(); i++){
        if(list.get(i) > biggestNum){
          biggestNum = list.get(i);
        }
      }
      return biggestNum;
    }
    public static ArrayList<Integer> productListVertical(ArrayList<Integer> myLi, int min, int max, int rowLen){
      ArrayList<Integer> runningList = new   ArrayList<Integer>();
      for(int i = min; i < myLi.size() - max; i++){
        runningList.add(productSummation(getDigitsVertical(myLi, min  + i, max + i, rowLen)));
      }
      return runningList;
  }
    public static int productSummation(ArrayList<Integer> myList){
    int runningResult = 1;
    for(int i = 0; i < myList.size(); i++){
      runningResult *= myList.get(i);
    }
    return runningResult;
  }
  public static ArrayList<Integer> getDigitsVertical(ArrayList<Integer> myList, int min, int max, int rowLen){
    ArrayList<Integer> runningResult = new ArrayList<Integer>();
    int c = 1;
    for(int i = min; i <= max * rowLen; i+= rowLen){
      c = myList.get(i);
      runningResult.add(c);
      if(min == (myList.size() - max)){
      return runningResult;
    }
    }
    return runningResult;
  }
}
Why do I get this error and how can I fix it?
 
    