Given a properly prepared
String array containing five elements, which
range of results could a
proper invocation of Arrays.binarySearch() produce?
A. 0 through 4
B. 0 through 5
C. -1 through 4
D. -1 through 5
E. -5 through 4
F. -5 through 5
G. -6 through 4
H. -6 through 5
Answer:
3 G is correct. If a match is found, binarySearch()will return the
index of the element that was matched. If no match is found, binarySearch() will return a negative number that,if inverted and then decremented, gives you the insertion point (array index) at which the
value searched on should be inserted into the array to maintain a
proper sort.
A, B, C, D, E, F, and H are incorrect based on the above. (Objective
6.5)
Can any one please expalin me why only G
Source KB Book