Home  >  Article  >  Java  >  Java Example - Determine whether arrays are equal

Java Example - Determine whether arrays are equal

黄舟
黄舟Original
2017-02-21 09:42:441373browse

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!



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn