This Java function below is not working as I expected, it's supposed to go through an array of numbers and if it finds a number in the array that is divisible by 2 with a remainder of 0, then it adds it to a new array and returns the new array at the end. Can you help debug the function and explain how why it's not working as expected?

public static List checkForEvens(int [] nums) {
    ArrayList anwer = new ArrayList<Integer>();
    for(int i = 0; i < nums.length; i++) {
    if(nums[i] / 2 == 0) {
    answer.add(nums[i]
     }  
   }
}
Certainly! The function 'checkForEvens' iterates through an array and if a number in the array is divisible by 2, then it gets added to 'answer' which is later returned.

The reason the function may not be returning the expected result is because of the if statement, 'if (nums[i] /2 == 0)'. The statement is looking for numbers that get divided by 2 in the array and equal 0, which doesn't align with what you expect the function to do. 

Instead, you want to use the modulo operator to check for the remainder of a number that is being divided by 2. If a number is divided by 2 and returns a remainder of 0, then we can assume that it's an even number. So, the small change of 'if (nums[i] % 2 == 0)' should solve your issue. 

I've rewritten the function below with the correction.

public static List checkForEvens(int [] nums) {
    ArrayList anwer = new ArrayList<Integer>();
    for(int i = 0; i < nums.length; i++) {
    if(nums[i] % 2 == 0) {
    answer.add(nums[i]
     }  
   }
}