Java AtomicBoolean get()方法及示例

Java AtomicBoolean get()方法及示例

java.util.concurrent.atomic.AtomicBoolean.get() 是java中的一个内置方法,用于返回日期型布尔的当前值。

语法

public final boolean get()

参数: 该函数不接受任何参数。

返回值 :该函数返回当前值

以下程序说明了上述函数。

程序1 :

// Java Program to demonstrates
// the get() function
  
import java.util.concurrent.atomic.AtomicBoolean;
  
public class GFG {
    public static void main(String args[])
    {
  
        // Initially value as false
        AtomicBoolean val
            = new AtomicBoolean(false);
  
        // Gets the current value
        boolean res = val.get();
  
        System.out.println("current value: "
                           + res);
    }
}

输出。

current value: false

程序2。

// Java Program to demonstrates
// the get() function
  
import java.util.concurrent.atomic.AtomicBoolean;
  
public class GFG {
    public static void main(String args[])
    {
  
        // Initially value as true
        AtomicBoolean val = new AtomicBoolean(true);
        // Gets the current value
        boolean res = val.get();
  
        System.out.println("current value: "
                           + res);
    }
}

输出。

current value: true

参考资料: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicBoolean.html#get-

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程