Tony Burrows wrote:
I know that in many C/C++ compilers using i++ is faster/ more efficient than
i = i+1.
Is it true for Java as well?
Well, I don't know, but I would think that it depends on the JVM and
compiler implementation, and of course the architechture it's run on, as
it is in C/C++
The main reason for the i++ being faster than an i=i+1 is that an
increment-instruction (if supported by the hardware) is a often a lot
faster than an addition-instruction. This is not always true - on many
RISC systems the time spent on these will be the same (one clock cycle).
But, all that being said, the compiler really should optimize the i=i+1
to be i++ anyways...
--
Michael Banzon
http://michael.banzon.dk/