What is the AtomicBoolean.toString() method in Java?
AtomicBoolean represents a boolean value that can be updated
AtomicBoolean is present in the java.util.concurrent.atomic package.
The toString() method of AtomicBoolean returns the AtomicBoolean value as a String value.
Syntax
public String toString()
Parameters
This method doesn’t take any parameters.
Return value
The toString() method returns the String representation of the AtomicBoolean object’s value.
Code
The code below demonstrates how to use the toString() method.
import java.util.concurrent.atomic.AtomicBoolean;class StringValue{public static void main(String[] args) {AtomicBoolean atomicBoolean = new AtomicBoolean(true);System.out.println("The String value of atomicBoolean is - " + atomicBoolean.toString());}}
Explanation
-
Line 1: We import the
AtomicBooleanclass. -
Line 4: We create a new object for the
AtomicBooleanclass with the nameatomicBooleanand the value10. -
Line 5: We use the
toString()method to get the value of theatomicBooleanobject as a string.