Concept Description:

• I ++ is an operation, for example, a= I ++, a= I, and I = I +1, so a==1
• For example, a=++ I, I = I +1, then a= I, so the result is a==2

Brief description:

• A = I ++ is the same thing as a= I; i = i+1;
• A =++ I = I +1; a=i
``````// i++
int temp = i;
i = i+1;
return temp;

// ++i
i = i + 1;
int temp = i;
return temp;

Copy the code``````

Detailed description:

• I++ is the increment after the increment, the principle is: first increment, and then return the value before increment
• ++ I is the previous addition, the principle is: first increment, and then return the value after increment

Exercises:

## The first question

``````int i = 0;
i = i++;
System.out.println("i = " + i);
Copy the code``````

## The second question

``````int a = 2;
int b = (3 * a++) + a;
System.out.println(b);
Copy the code``````

## The third question

``````int a = 2;
int b = a + (3 * a++);
System.out.println(b);
Copy the code``````

## The fourth question

``````int i = 1;
int j = 1;
int k = i++ + ++i + ++j + j++;
System.out.println(k);
Copy the code``````

## The fifth problem

``````int a = 0;
int b = 0;
a = a++;
b = a++;
System.out.println("a = " + a + ", b = " + b);
Copy the code``````

When I looked at the code, I found that ++ I was used in many places. For example, when deciding whether to expand the capacity in HashMap, (++size > threshold) was used to determine whether to expand the capacity. I found myself a little vague about the concepts of I ++ and ++ I, so I found some blogs to read and typed this post. The answers will be posted in the comments section of the article. If there is any incorrect place welcome to correct, hope this article can help you ~