how to check if an arraylist contains a value in java recursion

Solutions on MaxInterview for how to check if an arraylist contains a value in java recursion by the best coders in the world

showing results for - "how to check if an arraylist contains a value in java recursion"
Julia
01 Nov 2020
1public static boolean contains(ArrayList<Integer> list, int value) {
2        return contains(list, value, 0);
3}
4
5private static boolean contains(ArrayList<Integer> list, int value, int idx) {
6        boolean hasInt = false;
7        
8        if (idx < list.size()) {
9            if (list.get(idx) == value) {
10                hasInt = true;
11            } else {
12                hasInt = contains(list, value, idx + 1);
13            }
14        }
15        
16        return hasInt;
17}