What is faster:
int[] nums = [1, 4, 8, 2, etc...];
//access length each time?
for (int i : nums) {
i = nums.length * i;
}
OR...
int[] nums = [1, 4, 8, 2, etc...];
//store length off?
int length = nums.length;
for (int i : nums) {
i *= length;
}
Storing the length takes up space, but if you have to determine the length N times, that could slow it down. I'm wondering if nums.length is effectively stored off when the int[] is created, or if its dynamically determined each time referenced.