arr – the array to be searched
fromIndex – the index of the first element (inclusive) to be searched
toIndex - the index of the last element (exclusive) to be searched
key – the value to be searched for
The insertion point is defined as a point at which the specified key would be inserted: the index of the first element in the range greater than the key, or toIndex if all elements in the range are less than the specified key.
Note: This guarantees that the return value will be >= 0 if and only if the key is found.
byteArr[] = {10,20,15,22,35}
key = 22 to be searched between the range 2 to 4 in specified array.
Output: 3
charArr[] = {'g','p','q','c','i'}
key = p to be searched between the range 1 to 4 in specified array.
Output: 3
intArr[] = {1,2,3,4,5,6}
key = 3 to be searched between the range 1 to 4 in specified array.
Output: 2
doubleArr[] = {10.2,1.51,2.2,3.5}
key = 1.5 to be searched between the range 1 to 4 in specified array.
Output: -2 as it is the insertion point of 1.5
floatArr[] = {10.2f,15.1f,2.2f,3.5f}
key = 35.0 to be searched between the range 1 to 4 in specified array.
Output: -5
shortArr[] = {10,20,15,22,35}
key = 5 to be searched between the range 0 to 4 in specified array.
Output: -1