Java 中 long 累加器 intValue()方法,带示例
原文:https://www . geesforgeks . org/long 累加器-int value-method-in-Java-with-examples/
java。long 累加器. intValue() 是 java 中的一个内置方法,它在缩小基元转换后将当前值作为 int 返回。
语法:
public int intValue()
参数:该方法不接受任何参数。
返回值:该方法在收缩基元转换后将当前值作为 int 返回。
下面的程序说明了上述方法:
程序 1 :
// Program to demonstrate the intValue() method
import java.lang.*;
import java.util.concurrent.atomic.LongAccumulator;
public class GFG {
public static void main(String args[])
{
LongAccumulator num = new LongAccumulator(Long::sum, 0L);
// accumulate operation on num
num.accumulate(42);
num.accumulate(10);
// Print before intValue operation
System.out.println(" the old value is: " + num);
// intValues current value
num.intValue();
// Print after intValue operation
System.out.println("the current value is: " + num);
}
}
输出:
the old value is: 52
the current value is: 52
程序二 :
// Program to demonstrate the intValue() method
import java.lang.*;
import java.util.concurrent.atomic.LongAccumulator;
public class GFG {
public static void main(String args[])
{
LongAccumulator num = new LongAccumulator(Long::sum, 0L);
// accumulate operation on num
num.accumulate(4);
num.accumulate(4);
// Print before intValue operation
System.out.println(" the old value is: " + num);
// intValues current value
num.intValue();
// Print after intValue operation
System.out.println(" the current value is: " + num);
}
}
输出:
the old value is: 8
the current value is: 8
版权属于:月萌API www.moonapi.com,转载请注明出处