Java AtomicInteger intValue()方法及示例
java.util.concurrent.atomic.AtomicInteger.intValue() 是java中的一个内置方法,用于返回当前存储在数据类型为 int 的对象中的值 。
语法
public int intValue()
参数: 该函数不接受单一参数。
返回值 :该函数返回当前值。
下面的程序演示了该函数。
程序1 :
// Java program that demonstrates
// the intValue() function
import java.util.concurrent.atomic.AtomicInteger;
public class GFG {
public static void main(String args[])
{
// Initially value as 0
AtomicInteger val
= new AtomicInteger(0);
int res
= val.intValue();
// Prints the updated value
System.out.println("Current value: "
+ res);
}
}
输出。
Current value: 0
程序2
// Java program that demonstrates
// the intValue() function
import java.util.concurrent.atomic.AtomicInteger;
public class GFG {
public static void main(String args[])
{
// Initially value as 18
AtomicInteger val
= new AtomicInteger(18);
int res = val.intValue();
// Prints the updated value
System.out.println("Current value: "
+ res);
}
}
输出。
Current value: 18
参考资料: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicInteger.html#intValue-
极客教程