Share the most efficient and fastest looping code in Android development
- 2020-05-09 19:15:16
- OfStack
/* 1 (fastest) */
for (int i = initializer; i
>
= 0; i--) { ... }
/* 2, 2 */
int limit = calculateLoopLimit();
for (int i = 0; i
<
limit; i++) { ... }
/* 3 */
Type[] array = getMyArray();
for (Type obj : array) { ... } /* 4 */ for (int i = 0; i
<
array.length; i++) { ... }
/* 5 */
for (int i = 0; i
<
this.var; i++) { ... }
/* 6 */
for (int i = 0; i
<
obj.size(); i++) { ... }
/* 7 (slowest) */
Iterable
<
Type
>
list = getMyList();
for (Type obj : list) { ... }