Compare Object arrays in Java
Description
The following code shows how to compare Object arrays.
When comparing Object arrays, null elements are equal. If the elements are not null, Object.equals() is used.
Example
import java.util.Arrays;
/*from ww w.j a v a 2 s. c om*/
public class Main {
public static void main(String[] argv) throws Exception {
boolean b = Arrays.equals(new String[] { "a" }, new String[] { "a" });
System.out.println(b);
b = Arrays.equals(new String[] { null }, new String[] { null });
System.out.println(b);
b = Arrays.equals(new String[] { "a" }, new String[] { null });
System.out.println(b);
}
}
The code above generates the following result.
Home »
Java Tutorial »
Java Data Type »
Java Tutorial »
Java Data Type »