java.LongAccumulator.getThenReset()是Java中的一種內置方法,等效於get(),然後是reset()。首先,它獲取當前值,然後重置該值。
用法:
public long getThenReset()
參數:此方法不接受任何參數。
返回值:此方法返回複位前的值。
以下示例程序旨在說明上述方法:
程序1:
// Program to demonstrate the getThenReset() 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);
num.get();
// before getThenReset the value is
System.out.println(" the old value is: " + num);
;
// getThenResets current value
num.getThenReset();
// Print after getThenReset operation
System.out.println(" the current value is: " + num);
}
}
輸出:
the old value is: 52 the current value is: 0
程序2:
// Program to demonstrate the getThenReset() 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(2);
num.accumulate(1);
num.get();
// before getThenReset the value is
System.out.println(" the old value is: " + num);
// getThenResets current value
num.getThenReset();
// Print after getThenReset operation
System.out.println(" the current value is: " + num);
}
}
輸出:
the old value is: 3 the current value is: 0
相關用法
- Java DoubleAccumulator getThenReset()用法及代碼示例
- Java LongAccumulator get()用法及代碼示例
- Java LongAccumulator reset()用法及代碼示例
- Java LongAccumulator longValue()用法及代碼示例
- Java LongAccumulator doubleValue()用法及代碼示例
- Java LongAccumulator toString()用法及代碼示例
- Java LongAccumulator floatValue()用法及代碼示例
- Java LongAccumulator intValue()用法及代碼示例
- Java LongAccumulator accumulate()用法及代碼示例
- Java Java lang.Long.highestOneBit()用法及代碼示例
- Java Java lang.Long.byteValue()用法及代碼示例
- Java Java lang.Long.reverse()用法及代碼示例
- Java Java lang.Long.builtcount()用法及代碼示例
- Java Java lang.Long.numberOfLeadingZeros()用法及代碼示例
注:本文由純淨天空篩選整理自Twinkl Bajaj大神的英文原創作品 LongAccumulator getThenReset() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。