Java Example - Determine if Arrays are Equal
The following example demonstrates how to use the equals() method to determine if arrays are equal:
Main.java file
import java.util.Arrays;
public class Main {
public static void main(String[] args) throws Exception {
int[] ary = {1,2,3,4,5,6};
int[] ary1 = {1,2,3,4,5,6};
int[] ary2 = {1,2,3,4};
System.out.println("Is array ary equal to array ary1? :"
+Arrays.equals(ary, ary1));
System.out.println("Is array ary equal to array ary2? :"
+Arrays.equals(ary, ary2));
}
}
The output of running the above code is:
数组 ary 是否与数组 ary1相等? :true 数组 ary 是否与数组 ary2相等? :falseOther Extensions
Java Example