Check out example codes for "how to check if an arraylist contains a value in java recursion". It will help you in understanding the concepts better.

Code Example 1

public static boolean contains(ArrayList<Integer> list, int value) {
        return contains(list, value, 0);
}

private static boolean contains(ArrayList<Integer> list, int value, int idx) {
        boolean hasInt = false;
        
        if (idx < list.size()) {
            if (list.get(idx) == value) {
                hasInt = true;
            } else {
                hasInt = contains(list, value, idx + 1);
            }
        }
        
        return hasInt;
}

Learn ReactJs, React Native from akashmittal.com