javacodex.com
Java Examples
Java Examples
memu home questions

How to compare a Boolean with an AtomicBoolean?

AtomicBoolean and Boolean are not the same type of class. So how does one compare a Boolean with an AtomicBoolean?

Use the get method from the AtomicBoolean class.

See: https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/AtomicBoolean.html

Source: (Example.java)

import java.util.concurrent.atomic.AtomicBoolean;
 
public class Example {
 
    public static void main(String[] args) {
 
        Boolean b = new Boolean(true);
        AtomicBoolean ab = new AtomicBoolean(true);
 
        if (b == ab.get()) {
            System.out.println("TRUE");
        }
    }
}
 

Output:

# java Example
TRUE

Questions answered by this page:

How to compare AtomicBoolean with boolean value in java? Java comparing a boolean with an AtomicBoolean




Contact: javacodex@yahoo.com