Remove from the loop any execution code that does not need to be
executed on each pass.
Move any code that is repeatedly executed with the same result, and
assign that code to a temporary variable before the loop
("code motion").
Avoid method calls in loops when possible, even if this requires
rewriting or inlining.
Multiple access or update to the same array element should be done on
a temporary variable and assigned back to the array element when the
loop is finished.
Avoid using a method call in the loop termination test.
Use int data types preferentially, especially for
the loop variable.
Use System.arraycopy( ) for copying arrays.
Try to use the fastest tests in loops.
Convert equality comparisons to identity comparisons when possible.
Phrase multiple boolean tests in one expression so that they
"short circuit" as soon as
possible.
Eliminate unneeded temporary variables from loops.
Try unrolling the loop to various degrees to see if this improves
speed.