optimize ArrayList iteration