For Android development in general, is it worth it to do the following: (Example 1)
for(int x=0; x < largeObjectCollection.size(); x++){ largeObjectCollection.get(x).SomeValueOne = "Sample Value 1"; largeObjectCollection.get(x).SomeValueTwo = "Sample Value 2"; largeObjectCollection.get(x).SomeValueThree = "Sample Value 3" ;
In this implementation (example 2)
for(int x=0; x < largeObjectCollection.size(); x++){ SampleObjectIns myObject = largeObjectCollection.get(x); myObject.SomeValueOne = "Sample Value 1"; myObject.SomeValueTwo = "Sample Value 2"; myObject.SomeValueThree = "Sample Value 3" ;
I could not find a single performance violation when using .get()
several times instead of creating a new instance of this object at each iteration.
I think .get()
does not use many resources, since the position of the element is already known, but when working with many properties, it is best to just extract this object once, as shown in Example 2
Dayan source share