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

0

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

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;
}
Posted by: Guest on April-14-2020

Code answers related to "how to check if an arraylist contains a value in java recursion"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language