Java-arrays class-deepequals () and Equals () detailed

Source: Internet
Author: User

Deepequals and Equals are two static methods in the arrays class, and the main function is to compare two arrays.

See their nuances with the following code:

 public  class   Test { public  static  void   main (string[] args) {string[][] name1  = {{"G", "a", "O"},{"H", "U", "a", "N"}          , {"J", "I", "E" }};            string[][] name2  = {{"G", "a", "O"},{"H", "U", "a", "N"},{"J", "I", "E" }};    System.out.println (Arrays.equals (name1, name2));  //  false  System.out.println (Array S.deepequals (name1, name2)); //  true  }}  
 Public class Test {      publicstaticvoid  main (string[] args) {          = {"G", "a", "O", " H "," U "," a "," N "," J "," I "," E "};           = {"G", "a", "O", "H", "U", "a", "N", "J", "I", "E"};          System.out.println (Arrays.equals (name1, name2));       // true          System.out.println (Arrays.deepequals (name1, name2));  // true       }  }  

Summarize:

1. Deepequals is used to determine whether the two specified arrays are deeply equal to each other, and this method is suitable for nested arrays of arbitrary depths.

2, Equals is used to determine whether two arrays are equal, and returns true if two arrays contain the same elements in the same order, otherwise false is returned.

3, through the comparison of "code One" and "code two" we can draw a conclusion: if two arrays use equals to return true, then use deepequals also returns True, that is, the comparison of the two array is a one-dimensional array, the premise, There is no difference between equals and deepequals;

4, if you want to compare more than the array, you need to use the Deepequals method;

Java-arrays class-deepequals () and Equals () detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.