how to check if an arraylist contains a value in java recursion code example
Example: 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;
}