I have the code:
for(int i = 0; i < 99999; i++) {
minhaLista.get(i + x); //x é int e possui um valor qualquer
}
At some point the sum of i + x
results in a value greater than the size of the list.
If I execute this code I will get a IndexOutOfBoundsException
.
What is the best deal for this case?
Should I check for every iteration if (i + x) < minhaLista.size()
? Or should I catch the IndexOutOfBoundsException
?