Home >Java >javaTutorial >Java Example - Determine whether arrays are equal
The following example demonstrates how to use the equals () method to determine whether arrays are equal:
/* 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 output result of running the above code is:
数组 ary 是否与数组 ary1相等? :true 数组 ary 是否与数组 ary2相等? :false
The above is the Java example - judging arrays Whether the content is equal, please pay attention to the PHP Chinese website (www.php.cn) for more related content!