I have an error and I am trying to figure out how to fix it.
This is my code:
private static void checkAnomalies(Name[] list){
    Name[] temp = new Name[list.length];
    int anomalyCount = 0;
    int popTwo = 0;
    int popOne = 0;
    String[] anomalies = new String[1065];
    for (int i = 0; i < list.length; i++){
        temp[i] = list[i];
    }
    for (int decade = 0; decade < 11; decade++){
        for (int index = 0; index < temp.length; index++){
            int smallestIndex = getIndexOfSmallest(decade, index, temp);
            interchange(decade, index, smallestIndex, temp);
        }
        int rank = 0;
        for (int i = 0; i < temp.length; i += 2){
            popOne = temp[i].getPop(decade);
            popTwo = temp[i+1].getPop(decade);
            if (popOne != 0){
                rank++;
            }
            if (popOne  == rank && popTwo != rank){
                String decadeYear = decadeYears(decade);
                anomalies[anomalyCount] = "One name (" + temp[i].getName() + ") for " + decadeYear + ", rank " + temp[i].getPop(decade) + ".";
                anomalyCount++;
            }
            else if (popOne != rank && popTwo == rank){
                String decadeYear = decadeYears(decade);
                anomalies[anomalyCount] = "One name (" + temp[i+1].getName() + ") for " + decadeYear + ", rank " + temp[i+1].getPop(decade) + ".";
                anomalyCount++;
            }
            else if (popOne != rank && popTwo != rank){
                String decadeYear = decadeYears(decade);
                anomalies[anomalyCount] = "No names for " + decadeYear + ", rank " + temp[i].getPop(decade) + ".";
                anomalyCount++;
            }
        }
    }
}
the error I am getting is this:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4429
at NameApp.checkAnomalies(NameApp.java:495)
at NameApp.writeAnomaliesToFile(NameApp.java:260)
at NameApp.main(NameApp.java:44)
I know that list.length is equal to 4429 and I know that the error is at this line here
popTwo = temp[i+1].getPop(decade);
how can I still use this but not go over 4429.
 
     
    