Could someone explain the runtime and downsides of repeatedly accessing an array and if it is better to store the String value from the array as a temporary string. For example if I have an array of strings is it better to do
int paramLength = params.length;
for (int i=1; i<paramLength; i++){
or
for (int i=1; i<params.length; i++){
I would think the first option is better in the above case. The trade off being accessing the length inside the array object once and storing it vs. repeatedly accessing the length.
Also, once I'm inside the for loop and I need to use the string from the array multiple times is it better to store the String in the array as a local variable or to keep accessing the array and why is it better?
for (int i=1; i<paramLength; i++){
System.out.println(params[i]);
or
for (int i=1; i<paramLength; i++){
String temp = params[i];
System.out.println(temp);
or
for (String s: params)
System.out.println(s);
Sorry if this is repeated but I couldn't find more knowledge on the downsides of accessing these values inside the array vs storing it locally.