erickreutz erickreutz - 1 year ago 65
Java Question

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

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

Answer Source

++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