Question 4
Back to Exercise
What is the output of the following Java program?
import java.util.Arrays;
public class Main {
public static void main(String[] args) {
int[] a = {1, 2, 3};
int[] b = {1, 2, 3};
int[][] x = {{1}, {2}};
int[][] y = {{1}, {2}};
System.out.println((a == b) + " " + a.equals(b) + " " + Arrays.equals(a, b) + " "
+ Arrays.equals(x, y) + " " + Arrays.deepEquals(x, y));
}
}
- A false false true false true Correct
- B true true true true true
- C false true true true true
- D false false true true true
Correct Answer: Option A
For nested arrays Arrays.equals compares the row references; only deepEquals compares the contents of the rows.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!