Java.util.concurrent.atomic.atomic boolean.set ()是内置于Java中的方法,用于更新以前的值并将其设置为参数传递的新值。
使用方法:
publicfinalvoidset (布尔新) )。
参数:此函数接受要更新的单个必需参数newVal。
返回值:此函数不返回任何内容。
下面的示例程序是为了说明上述功能。
样本1:
//Java程序hat demonstrates
//the set ()函数
import Java.util.concurrent.atomic.atomic boolean;
公共类gfg {
publicstaticvoidmain (字符串args [ ] ) ) ) ) )。
{
//Initially value as false
自动布尔值
=newatomicboolean(false );
系统. out.println (previous value : )。
val;
val.set (真;
//prints the更新值
system.out.println (' current value : '
val;
}
}
输出:
Previous value: false
current value :真
样本2:
//Java程序hat demonstrates
//the set ()函数
import Java.util.concurrent.atomic.atomic boolean;
公共类gfg {
publicstaticvoidmain (字符串args [ ] ) ) ) ) )。
{
//Initially value as true
自动布尔值
=newatomicboolean(true;
系统. out.println (previous value : )。
val;
val.set (假;
//prints the更新值
system.out.println (' current value : '
val;
}
}
输出:
previous value :真
Current value: false