Tuesday, November 5, 2013

Usage of for loop styles in Collections..9/10

Example 1:

for (int i=0, n=list.size(); i < n; i++)
         list.get(i);
 
runs faster than this loop:
     for (Iterator i=list.iterator(); i.hasNext(); )
         i.next();

source: http://docs.oracle.com/javase/6/docs/api/java/util/RandomAccess.html

No comments:

Post a Comment