Of course startIndex == endIndex means there is one element whose length must be computed... Changed >= into >