I have 2 pieces of code:
First one:
List<Integer> integers = new ArrayList<>();
integers.add(0);
integers.add(1);
//Assume that list will always have the same values with loop indices.
//Also any of the methods will not change the size and elements of the list.
for (int i=0;i<integers.size();i++) {
if (0 == integers.get(i)) {
foo();
}
else if (1 == integers.get(i)) {
bar();
}
}
Second one:
foo();
bar();
I know both code snippets are doing the same thing but is there any difference in performance or does JVM doing something to optimize the first snippet in compile time or runtime?