I've a code something similar to this.
public static final int[] VALUES = {1,2,3,4,5,6};
for(int i=0; i< VALUES.length; i++) {
//Do something
}
Is it good to have VALUES.length
as part of loop. Should I assign it to a variable and use it here?
In case of String array, I've seen it's been doing this way.
public static final String[] STR_VALUES = {"apple", "orange", "butterfly"};
int length = STR_VALUES.length();
for(int i=0; i< VALUES.length; i++) {
//Do something
}
Since it's a performance optimization that we need not compute the length again and again. But in the case of int[] it looks like I'm using instance variable of a class. But these are primitives where does class coming into picture here? I'm getting confused.
How this is process? From where Do we get the value from? How can I see it?