public class Test { public static void main(String[] args) { LinkedList l = new LinkedList(); for ( int i=0; i<1000000; i++ ) { l.addFirst(new Integer(i)); } System.gc(); System.gc(); System.gc(); long start = System.currentTimeMillis(); l.test(); long stop = System.currentTimeMillis(); System.out.println( "inside, time in ms is " + (stop-start) ); System.gc(); System.gc(); System.gc(); start = System.currentTimeMillis(); Iterator i = l.iterator(); while (i.hasNext()) { Integer x = i.next(); } stop = System.currentTimeMillis(); System.out.println( "outside (iterator), time in ms is " + (stop-start) ); } }