JAVA : Right way to find the list size in loop to save memory ?

JAVA : Right way to find the list size in loop to save memory ?

better way to find the list size once and limiting the scope of variables.

  for( int i=0 , n=test.size();i<n;i++) {
            System.out.println(test.get(i));
        }

After 1.5 java we can use for each

  for(int a : test) {
            System.out.println(a);
        }