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.
public String toString()
This method doesn’t take any parameters.
The toString()
method returns the String
representation of the AtomicBoolean
object’s value.
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());}}
Line 1: We import the AtomicBoolean
class.
Line 4: We create a new object for the AtomicBoolean
class with the name atomicBoolean
and the value 10
.
Line 5: We use the toString()
method to get the value of the atomicBoolean
object as a string.