DEVFYI - Developer Resource - FYI

The following statement prints true or false, why?

Java Interview Questions and Answers (part 1)


(Continued from previous question...)

163. The following statement prints true or false, why?

byte[] a = { 1, 2, 3 };,
byte[] b = (byte[]) a.clone();
System.out.println(a == b);
The false will be printed out. Because the two arrays have distinctive memory addresses. Starting in Java 1.2, we can use java.util.Arrays.equals(a, b) to compare whether two arrays have the same contents.

(Continued on next question...)

Other Interview Questions