Method void
test()
0 aconst_null
1 astore_1
2 iconst_0
3 istore_2
4 goto 15
7 iload_2
8 invokestatic #2 <Method java.lang.String valueOf(int)>
11 astore_1
12 iinc 2 1
15 iload_2
16 bipush 10
18 if_icmplt 7
21 return
Method void test()
0 iconst_0
1 istore_1
2 goto 13
5 iload_1
6 invokestatic #2 <Method java.lang.String valueOf(int)>
9 astore_2
10 iinc 1 1
13 iload_1
14 bipush 10
16 if_icmplt 5
19 return
The only difference is the additional aconst_null & astore_1 in the first solution.
So in most applications there won't be any measurable difference between the two solutions, especially as the modern optimizing hotspot engine might even drop the aconst_null, as it isn't really needed here.
Conclusion: Choose the solution that is better readable. In fact
you should always follow this advice until really *experiencing* a performance problem. See
http://c2.com/cgi/wiki?OptimizeLater [ January 18, 2002: Message edited by: Ilja Preuss ]
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus