java.LongAccumulator.reset()是Java中的一種內置方法,該方法重置變量以保持對標識值的更新。
用法:
public void reset()
參數:該方法不接受任何參數。
返回值:該方法返回重置值。
以下示例程序旨在說明上述方法:
程序1:
// Program to demonstrate the reset() 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(10);
// resets current value
num.reset();
// Print after reset operation
System.out.println(" the current value is: " + num);
}
}
輸出:
the current value is: 0
程序2:
// Program to demonstrate the reset() 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);
// resets current value
num.reset();
// Print after reset operation
System.out.println(" the current value is: " + num);
}
}
輸出:
the current value is: 0
參考: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/LongAccumulator.html#reset–
相關用法
- Java LongAccumulator get()用法及代碼示例
- Java LongAccumulator intValue()用法及代碼示例
- Java LongAccumulator accumulate()用法及代碼示例
- Java LongAccumulator doubleValue()用法及代碼示例
- Java LongAccumulator floatValue()用法及代碼示例
- Java LongAccumulator toString()用法及代碼示例
- Java LongAccumulator getThenReset()用法及代碼示例
- Java LongAccumulator longValue()用法及代碼示例
- Java Scanner reset()用法及代碼示例
- Java StringReader reset()用法及代碼示例
- Java CollationElementIterator reset()用法及代碼示例
- Java CharArrayWriter reset()用法及代碼示例
- Java MessageDigest reset()用法及代碼示例
- Java Matcher reset()用法及代碼示例
- Java DoubleAccumulator reset()用法及代碼示例
注:本文由純淨天空篩選整理自Twinkl Bajaj大神的英文原創作品 LongAccumulator reset() method in Java with examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。