erickreutz erickreutz - 2 years ago 109
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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download