Skip to content

Instantly share code, notes, and snippets.

@shohei
Created December 27, 2011 06:16
Show Gist options
  • Save shohei/1522854 to your computer and use it in GitHub Desktop.
Save shohei/1522854 to your computer and use it in GitHub Desktop.
My first public gist
import java.util.ArrayList;
// "len" scope into the for statement
class StopAtHome {
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < 100000; i++) {
list.add(i);
}
// print only even number
for (int i = 0, len = list.size(); i < len; i++) {
if (i % 2 == 0) {
System.out.println(list.get(i);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment