How to compare Arrays in Java � Equals vs deepEquals Example
java.util.Arrays class provides equals() and deepEquals() method to compare two Arrays in Java. Both of these are overloaded method to compare primitive arrays e.g. int, long, float, double and Object arrays e.g. Arrays.equals(Object[] , Object[]). Arrays.equals() returns true if both Arrays which it is comparing are null If both arrays pointing to same Array Object or they must be of the same length and contains the same element in each index. In all other cases, it returns false. Arrays.equals() calls equals() method of each Object while comparing Object arrays. One of the tricky question in Java related to Array comparison is Difference between Arrays.equals() and Arrays.deepEquals() method. Since both equals and deepEquals is used for array comparison, what is the difference between them becomes important. The short answer of this questions is that, Array's equals() method does not perform deep comparison and fails logical comparison in case of nested Array, on other hand deepEquals() perform deep comparison and returns logical comparison in case of nested array.
Comments
Post a Comment
-Berkomentarlah yang baik dan rapi.
-Menggunakan link aktif akan dihapus.