Java Prefix and Postfix Operators

The operators ++ and -- operators’ order matters:

  • Prefix applies operation before returning value
  • Postfix applies operation after returning value
int someValue = 5;
System.out.println(++someValue) // 6
System.out.println(someValue)   // 6

int someOtherValue = 5;
System.out.println(someOtherValue++) // 5
System.out.println(someOtherValue)   // 6