Finds and returns the relative index of the first mismatch between two
short
arrays over the specified ranges, otherwise return -1 if no
mismatch is found. The index will be in the range of 0 (inclusive) up to
the length (inclusive) of the smaller range.
If the two arrays, over the specified ranges, share a common prefix then the returned relative index is the length of the common prefix and it follows that there is a mismatch between the two elements at that relative index within the respective arrays. If one array is a proper prefix of the other, over the specified ranges, then the returned relative index is the length of the smaller range and it follows that the relative index is only valid for the array with the larger range. Otherwise, there is no mismatch.
Two non- null
arrays, a
and b
with specified
ranges [ aFromIndex
, atoIndex
) and
[ bFromIndex
, btoIndex
) respectively, share a common
prefix of length pl
if the following expression is true:
pl >= 0 &&
pl < Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex) &&
Arrays.equals(a, aFromIndex, aFromIndex + pl, b, bFromIndex, bFromIndex + pl) &&
a[aFromIndex + pl] != b[bFromIndex + pl]
Note that a common prefix length of 0
indicates that the first
elements from each array mismatch.
Two non- null
arrays, a
and b
with specified
ranges [ aFromIndex
, atoIndex
) and
[ bFromIndex
, btoIndex
) respectively, share a proper
if the following expression is true:
(aToIndex - aFromIndex) != (bToIndex - bFromIndex) &&
Arrays.equals(a, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex),
b, 0, Math.min(aToIndex - aFromIndex, bToIndex - bFromIndex))
a | the first array to be tested for a mismatch | |
aFromIndex | the index (inclusive) of the first element in the first array to be tested | |
aToIndex | the index (exclusive) of the last element in the first array to be tested | |
b | the second array to be tested for a mismatch | |
bFromIndex | the index (inclusive) of the first element in the second array to be tested | |
bToIndex | the index (exclusive) of the last element in the second array to be tested |
-1
.
IllegalArgumentException
| if aFromIndex > aToIndex or
if bFromIndex > bToIndex | |
ArrayIndexOutOfBoundsException
| if aFromIndex < 0 or aToIndex > a.length or
if bFromIndex < 0 or bToIndex > b.length | |
NullPointerException
| if either array is null |
Diagram: Arrays