You could do this: Convert your array to a list and sort it. Pick the first index, and call lastIndexOf(obj) on the value. Do this for each new value you encounter, calculate the range of the value and store the results of the biggest range in a variable.