erickreutz erickreutz - 6 months ago 10
Java Question

Is there a difference between x++ and ++x in java?

Is there a difference between ++x and x++ in java?

Answer

++x is called preincrement while x++ is called postincrement.

int x = 5, y = 5;

System.out.println(++x); // outputs 6
System.out.println(x); // outputs 6

System.out.println(y++); // outputs 5
System.out.println(y); // outputs 6