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