java.LongAccumulator.toString()是java中的一個內置方法,該方法返回LongAccumulator實例的當前值的String表示形式。
用法:
public String toString()
參數:此方法不接受任何參數。
返回值:此方法返回當前值的字符串表示形式。
以下示例程序旨在說明上述方法:
程序1:
// Program to demonstrate the toString() 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 toString the value is
System.out.println(" the old value is: " + num);
;
// toStrings current value
num.toString();
// Print after toString operation
System.out.println(" the current value is: " + num);
}
}
輸出:
the old value is: 52 the current value is: 52
程序2:
// program to demonstrate the toString() 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(5);
num.accumulate(10);
num.get();
// before toString the value is
System.out.println(" the old value is: " + num);
// toStrings current value
num.toString();
// Print after toString operation
System.out.println(" the current value is: " + num);
}
}
輸出:
the old value is: 15 the current value is: 15
參考: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/LongAccumulator.html#toString–
相關用法
- Java LongAccumulator get()用法及代碼示例
- Java LongAccumulator intValue()用法及代碼示例
- Java LongAccumulator longValue()用法及代碼示例
- Java LongAccumulator accumulate()用法及代碼示例
- Java LongAccumulator reset()用法及代碼示例
- Java LongAccumulator getThenReset()用法及代碼示例
- Java LongAccumulator doubleValue()用法及代碼示例
- Java LongAccumulator floatValue()用法及代碼示例
- Java CharArrayWriter toString()用法及代碼示例
- Java Field toString()用法及代碼示例
- Java Currency toString()用法及代碼示例
- Java ZoneId toString()用法及代碼示例
- Java Signature toString()用法及代碼示例
- Java Byte toString()用法及代碼示例
- Java AtomicInteger toString()用法及代碼示例
注:本文由純淨天空篩選整理自Twinkl Bajaj大神的英文原創作品 LongAccumulator toString() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。