-1
 public void push(E element) {
    if (size == elements.length) {
        resize(); // doubel of size
    }
    elements[size++] = element;
}


public E pop() {
    if (size == 0) {
        throw new java.util.EmptyStackException();
    }
    E element = elements[--size];
    elements[size] = null; // set null in last top
    return element;
}

what is the difference between a++ and ++a or a-- and --a in java

thanks

Wooble
  • 84,802
  • 12
  • 102
  • 128
Ghadeer
  • 53
  • 1
  • 1
  • 3

1 Answers1

20

a++ or a-- is postfix operation, meaning that the value of a will get changed after the evaluation of expression.

++a or --a is prefix operation, meaning that the value of a will get changed before the evaluation of expression.

lets assume this;

a = 4;

b = a++; // first b will be 4, and after this a will be 5

// now a value is 5
c = ++a; // first a will be 6, then 6 will be assigned to c

Refer this answer also.

Community
  • 1
  • 1
Denim Datta
  • 3,682
  • 3
  • 26
  • 53