I had an impression that in for loop condition, using a variable in place of the method call to string function length()
is always better. Though it seems that it is just opposite as analysed by Saint Hill in the following answer
https://stackoverflow.com/a/11876086/6517886
for (int i = 0; i < data.length(); i++) {
...
}
is faster than
final int len = data.length();
for (int i = 0; i < len; i++) {
...
}
What is the reason?