| Code with Finding: |
class ArrayUtils {
/**
* <p>Finds the last index of the given value in the array starting at the given index.</p>
*
* <p>This method returns {@link #INDEX_NOT_FOUND} (<code>-1</code>) for a <code>null</code> input array.</p>
*
* <p>A negative startIndex will return {@link #INDEX_NOT_FOUND} (<code>-1</code>). A startIndex larger than the
* array length will search from the end of the array.</p>
*
* @param array the array to traverse for looking for the object, may be <code>null</code>
* @param valueToFind the value to find
* @param startIndex the start index to travers backwards from
* @return the last index of the value within the array,
* {@link #INDEX_NOT_FOUND} (<code>-1</code>) if not found or <code>null</code> array input
*/
public static int lastIndexOf(double[] array, double valueToFind, int startIndex) {
if (ArrayUtils.isEmpty(array)) {
return INDEX_NOT_FOUND;
}
if (startIndex < 0) {
return INDEX_NOT_FOUND;
} else if (startIndex >= array.length) {
startIndex = array.length - 1;
}
for (int i = startIndex; i >= 0; i--) {
if (valueToFind == array[i]) {
return i;
}
}
return INDEX_NOT_FOUND;
}
}
|