public void zero() {
int sum = 0;
for (int i = 0; i < mArray.length; ++i) {
sum += mArray[i].mSplat;
}
}
public void one() {
int sum = 0;
Foo[] localArray = mArray;
int len = localArray.length;
for (int i = 0; i < len; ++i) {
sum += localArray[i].mSplat;
}
}
public void two() {
int sum = 0;
for (Foo a : mArray) {
sum += a.mSplat;
}
}
Quoting https://developer.android.com/training/articles/perf-tips.html#Loops it's recommend to use 'for each loop syntax' to achieve better performance. But on the other hand the article says that it does not make any difference for devices with JIT to use zero() or two() whereas zero() is the slowest.
Ive also found articles where it's not recommend to use two() but one() because a for each loop may create garbage.
I want to know what is the best to iterate through all elements of an Array Datatype from LibGDX.
Here are some articles: https://github.com/libgdx/libgdx/wiki/Collections https://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/utils/Array.html
I'm still confused