What is the AtomicBoolean.get() method in Java?
AtomicBoolean represents a boolean value that can be updated
AtomicBoolean is present in the java.util.concurrent.atomic package.
The get method of AtomicBoolean can be used to get the value present in the AtomicBoolean object.
Syntax
public final boolean get()
Arguments
This method takes no arguments.
Return value
This method returns the value present in the AtomicBoolean object.
Example
The below code demonstrates how to use the get method:
import java.util.concurrent.atomic.AtomicBoolean;class Get{public static void main(String[] args) {AtomicBoolean atomicBoolean = new AtomicBoolean(true);boolean val = atomicBoolean.get();System.out.println("The value in the atomicBoolean object is " + val);}}
Explanation
- Line 1: We import the
AtomicBooleanclass. - Line 4: We create a new object for the
AtomicBooleanclass with the nameatomicBooleanand with the valuetrue. - Line 5: We use the
getmethod of theatomicBooleanand store it to the boolean variableval, then print the value.