Performance of program is depend on how much time your code is taking to produce the output, and Statement/Loops/Conditions which take more time to execute it is natural that peace of code will consume more memory then other code which take less time to generate the output.
As per your code concern, 1st loop statement where you assigning final Object on every iteration is takes more time as compare to second loop statement where it assign to same object every time.
What I tried in my local linux(Ubuntu) box, 1st statement take 18 milliseconds while 2nd statement takes only 15 seconds, so I guess 2nd statement will be more appropriate.
Code which I tried locally:
import java.util.ArrayList;
import java.util.List;
public class Solution8 {
public static void main(String[] args) {
List<String> lis = new ArrayList<String>();
for (int i = 0; i <= Math.pow(10, 5); i++) {
lis.add(i + "");
}
long startTime = System.currentTimeMillis();
for (int i = 0; i <= Math.pow(10, 5); i++) {
final Object cur1 = lis.get(i);
}
long endTime = System.currentTimeMillis();
System.out.println("1st : "+(endTime-startTime)); // 18 milliseconds
Object cur;
long startTime2 = System.currentTimeMillis();
for (int i = 0; i <= Math.pow(10, 5); i++) {
cur = lis.get(i);
}
long endTime2 = System.currentTimeMillis();
System.out.println("2nd : "+(endTime2-startTime2)); // 15 milliseconds
}
}
Hope this will help.