I am not understanding what is meant by prefix in the below description from API.
public static int compare( int[] a, int[] b): Compares two int arrays lexicographically. If the two arrays share a common prefix then the lexicographic comparison is the result of comparing two elements, as if by Integer.compare( int, int), at an index within the respective arrays that is the prefix length. Otherwise, one array is a proper prefix of the other and, lexicographic comparison is the result of comparing the two array lengths. A null array reference is considered lexicographically less than a non-null array reference. Two null array references are considered equal. It returns 0 if the first and second array are equal and contain the same elements in the same order; a value less than 0 if the first array is lexicographically less than the second array; and a value greater than 0 if the first array is lexicographically greater than the second array.
public static int mismatch( int[] a, int[] b): Finds and returns the index of the first mismatch between two int arrays, 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 array.the two arrays share a common prefix then the returned index is the length of the common prefix and it follows that there is a mismatch between the two elements at that index within the respective arrays. If one array is a proper prefix of the other then the returned index is the length of the smaller array and it follows that the index is only valid for the larger array. Otherwise, there is no mismatch.
Code: Select all
int[] a1 = {11};
int[] a2 = {11,1112,1113,1114};
System.out.println(Arrays.compare(a1, a2));
System.out.println(Arrays.mismatch(a1, a2));
Code: Select all
-3
1
I am trying to use that understanding to figure out why this code would give me a '-3' and '1' as answer. I don't get it. Would appreciate some pointers. Thank you.