I need to increment AtomicInteger twice, like: ++i; ++i; By the endless ciycle, i want to increment counter twice and check it on the parity. But i'm always getting the variable which was incremented once. How to fix it?
AtomicInteger counter = new AtomicInteger(100);
counter.addAndGet(2);
System.out.println(counter);
or
AtomicInteger counter = new AtomicInteger(100);
counter.incrementAndGet();
counter.incrementAndGet();
System.out.println(counter);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With