I have the following code.
import java.util.Arrays;
public class Practice {
public static void main(String[] args) {
System.out.println(checkEquality({1,2,3},{1,2,3}));
}
public static boolean checkEquality(int[] a, int[] b) {
return Arrays.equals(a,b);
}
}
I am trying to write a method that checks for equality between two arrays of type int. The code as written doesn't compile, giving me an illegal start of expression error for line 11 (the one which has the print statement). However if I first define two arrays in the main method
int[] a= {1,2,3};
int[] b= {1,2,3};
and then change
System.out.println(checkEquality({1,2,3},{1,2,3}));
to System.out.println(checkEquality(a,b));
the code compiles and works as it should, giving me true.
My question: why can't I input the two arrays that I want to check for equality directly into the print statement? This has worked with all other methods that didn't have array, ex expressions involving integers and strings. Am I doing something wrong here or is this generally not possible? If so, why?