Java performance for loop -


this question has answer here:

i have algorithm for loops, looks like:

for(a : collection) {   (b : a.collection) {      (c : b.collection) {         c instance      }    }  } 

what best way optimize performance of nested loops?

for example use linkedhashmap?

thank you.

it program spend of time in do c instance part. in case, optimizations not worthwhile.

aside that, iteration speed depends on type of collection. arrays , arraylist fastest. iteration on linkedlist , other containers slower because element access requires additional indirections. vector slower because of synchronization overhead.

optimization effective inner loop because executed more outer ones.


Comments