If I have input 1,2,3,4,5,6,7,8,8,8 there will be an error because, as I have figured it out, at the end ".equals(listOfNumbers.get(i + 1) " this part of code will be = 10 and it will give an error. However, I don't know how to modify the code to accept the final value as well. Please offer me some guidance, to get to the correct reasoning! Thank you!
public class Solution {

    private static int count = 1;
    private static int maxCount = 1;

    public static void main(String[] args) throws IOException {
        //write your code here
        ArrayList<Integer> listOfNumbers = new ArrayList<>();

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        for (int i = 0; i < 10; i++) {
            listOfNumbers.add(Integer.parseInt(reader.readLine()));
        }

        for (int i = 0; i < 10; i++) {
            if (listOfNumbers.get(i).equals(listOfNumbers.get(i + 1))) {
                count++;
            } else if (maxCount < count) {
                maxCount = count;
                count = 1;
            }
        }
        System.out.println(maxCount);
    }
}