The following statement prints true or false, why?

Q

The following statement prints true or false, why?

✍: Guest

A

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.

2012-09-11, 2268👍, 0💬