AtomicInteger get() method in Java with examples Last Updated : 31 Jan, 2019 Comments Improve Suggest changes Like Article Like Report The java.util.concurrent.atomic.AtomicInteger.get() is an inbuilt method in java which returns the current value which is of date-type int. Syntax: public final int get() Parameters: The function does not accepts any parameter. Return value: The function returns the current value Program below demonstrates the function: Program 1: Java // Java Program to demonstrates // the get() function import java.util.concurrent.atomic.AtomicInteger; public class GFG { public static void main(String args[]) { // Initially value as 0 AtomicInteger val = new AtomicInteger(0); val.addAndGet(7); // Prints the updated value System.out.println("Previous value: " + val); // Gets the current value int res = val.get(); System.out.println("current value: " + res); } } Output: Previous value: 7 current value: 7 Program 2: Java // Java Program to demonstrates // the get() function import java.util.concurrent.atomic.AtomicInteger; public class GFG { public static void main(String args[]) { // Initially value as 18 AtomicInteger val = new AtomicInteger(18); val.addAndGet(7); // Prints the updated value System.out.println("Previous value: " + val); // Gets the current value int res = val.get(); System.out.println("current value: " + res); } } Output: Previous value: 25 current value: 25 Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicInteger.html#get-- Comment More infoAdvertise with us Next Article AtomicInteger get() method in Java with examples G gopaldave Follow Improve Article Tags : Java Java - util package Java-Functions Java-AtomicInteger Practice Tags : Java Similar Reads AtomicIntegerArray get() method in Java with Examples The Java.util.concurrent.atomic.AtomicIntegerArray.get() is an inbuilt method in java that gets the current value at any position of the AtomicIntegerArray. This method takes the index value as the parameter and returns the value at this index. Syntax: public final int get(int i) Parameters: The fun 2 min read AtomicInteger getAndSet() method in Java with examples The java.util.concurrent.atomic.AtomicInteger.getAndSet() is an inbuilt method in java that sets the given value to the value passed in the parameter and returns the value before updation which is of data-type int. Syntax: public final int getAndSet(int val) Parameters: The function accepts a single 2 min read AtomicInteger getAndAdd() method in Java with examples The java.util.concurrent.atomic.AtomicInteger.getAndAdd() is an inbuilt method in java that adds the given value to the current value and returns the value before updation which is of data-type int. Syntax: public final int getAndAdd(int val) Parameters: The function accepts a single mandatory param 2 min read AtomicLong get() method in Java with examples The Java.util.concurrent.atomic.AtomicLong.get() is an inbuilt method in java which returns the current value which is of date-type long. Syntax: public final long get() Parameters: The function does not accepts any parameter. Return value: The function returns the current value Below programs illus 1 min read AtomicInteger set() method in Java with examples The java.util.concurrent.atomic.AtomicInteger.set() is an inbuilt method in java that updates the previous value and sets it to a new value which is passed in the parameter. Syntax: public final void set(int newVal) Parameters: The function accepts a single mandatory parameter newVal which is to be 1 min read Like