QUIZ: Does this code have issues?
Over my holidays I had some time to read some books from cover to cover. Since my family requested a good amount of attention, I managed to finish only two, but this is fine as I'm in the middle of the next.
Where is the issue in this code?
There are many ways to iterate through lists in Java. One of my favorite is this one:for (int i = 0; i < list.size(); ++i) {
Object obj = list.get(i);
// do something
}I developed a habit to change it into this form:for (int i = 0, size = list.size(); i < size; ++i) {
Object obj = list.get(i);
// do something
}It is at least faster then the first version. Yes, it is. Consider a type of Vector with all methods synchronized for the list...
But, where is the issue?