![]() |
VOOZH | about |
The mismatch() method in Java, available in the java.util.Arrays class, is used to compare two arrays element by element. It returns the index of the first position where the elements differ, helping to quickly identify differences between arrays.
Index mismatch for arrays: 2
Note: If all corresponding elements match and one array is shorter, mismatch() returns the length of the smaller array.
Arrays.mismatch( a , b );
Parameters: The above method accepts the following parameters:
Return value:
Note: The data type of both arrays must be the same, and this method follows zero-based indexing.
Example 1 : For Identical Arrays
Index mismatch for arrays: -1
It seems that it work with int Array only but this is not the case we can use it with different data types and with different length too as mentioned below:
Arrays are equal : -1 Arrays are not equal : 1