List<String> objList = getData();
for (int i = 0; i < objList.size(); i++) { // Noncompliant
// execute code
}
When iterating over any collection, fetch the size of the collection in advance to avoid fetching it on each iteration. This saves CPU cycles, and therefore consumes less power.
List<String> objList = getData();
for (int i = 0; i < objList.size(); i++) { // Noncompliant
// execute code
}
List<String> objList = getData();
int size = objList.size();
for (int i = 0; i < size; i++) {
// execute code
}