Java instance - to determine whether the same array
The following example demonstrates how to use the equals () method to determine whether the array is equal to:
/* author by w3cschool.cc 文件名:Main.java */ 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("数组 ary 是否与数组 ary1相等? :" +Arrays.equals(ary, ary1)); System.out.println("数组 ary 是否与数组 ary2相等? :" +Arrays.equals(ary, ary2)); } }
The above code is run output is:
数组 ary 是否与数组 ary1相等? :true 数组 ary 是否与数组 ary2相等? :false