Out of curiosity, you can check the generated bytecode.
This program:
public static void main(String args[]) {
int i = 1; //bytecode 0, 1
i++; //bytecode 2
++i; //bytecode 5
int a = ++i; //bytecode 8, 11, 12
int b = i++; //bytecode 13, 14, 17
}
generates the following bytecode:
public static void main(java.lang.String[]);
Code:
0: iconst_1
1: istore_1
2: iinc 1, 1
5: iinc 1, 1
8: iinc 1, 1
11: iload_1
12: istore_2
13: iload_1
14: iinc 1, 1
17: istore_3
18: return
So you can see that pre and post fix operators are strictly identical from a bytecode perspective (apart from the order of the operations).
If and when the JIT compiles that part of your code, all bets are off. For example, the code above, as is, could be compiled as a no-op because it has no side effects.
x++
and I avoid using++
or--
in expressions. That is, I only use the statementx++;
(except when part of a for-loops iterator, where it might befor(..; ..; x++, y++)
, etc). – Memento