Deepequals and equals are the two static methods of the arrays class in Java, but what is the difference between them?
Code One,
Import Java.util.arrays;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)); FalseSystem.out.println (Arrays.deepequals (name1, name2));//True}}
Code two,
Import Java.util.arrays;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)); TrueSystem.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;
Two methods of the arrays class in Java: Deepequals and equals