• Post Reply Bookmark Topic Watch Topic
  • New Topic

getAndIncrement() Vs incrementAndGet()  RSS feed

 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between getAndIncrement() and incrementAndGet() in java.util.concurrent.atomic.AtomicInteger ? Is it similar to pre-increment and post-increment ?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you look at your post you will see that AtomicInteger is underlined - it is a link to the API. Click on it and read the descriptions of the methods. Do you understand the differences now?
 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already read the API/ java doc description. It has same description for both.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kri shan wrote:I already read the API/ java doc description. It has same description for both.

No it doesn't. Re-read, and look for differences.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:
kri shan wrote:I already read the API/ java doc description. It has same description for both.

No it doesn't. Re-read, and look for differences.



Yeah. It may only be a one word difference -- but it is an important difference.

Henry
 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it.... getAndIncrement() returns previous value and incrementAndGet() returns updated value.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!