What will be printed as a result of this code?

import java.util.Arrays;
class ArraysComparing {
    public static void main(String...args) {
        int[] i1[] = {{1,2,3}, {0,0,0}};
        int[][] i2 = {{1,2,3}, {0,0,0,}};
        int[][] i3 = new int[2][3];
        System.arraycopy(i1, 0, i3, 0, i3.length);
        System.out.println(Arrays.equals(i1, i2));
        System.out.println(Arrays.equals(i1, i3));
        System.out.println(Arrays.deepEquals(i1, i2));
    }
}
Explanation
In arrays i1 and i2 the links to nested arrays are different, so the first equals returns false.
In the second case, the links will be the same correspondingly true.
In the third case, a comparised elements are all the same, so true

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Cosmo
Sign Up Now
or Subscribe for future quizzes