Home > Java > javaTutorial > body text

Java Example - Determine whether arrays are equal

黄舟
Release: 2017-02-21 09:42:44
Original
1326 people have browsed it

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));
   }
}
Copy after login

The output result of running the above code is:

数组 ary 是否与数组 ary1相等? :true
数组 ary 是否与数组 ary2相等? :false
Copy after login

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!



Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!