java.DoubleAdder.toString()是java中的一個內置方法,該方法返回sum()方法的String表示形式。創建類的對象時,其初始值為零。
用法:
public String toString()
參數:此方法不接受任何參數。
返回值:該方法返回總和的字符串表示形式。
以下示例程序旨在說明上述方法:
程序1:
// Program to demonstrate the toString() method
import java.lang.*;
import java.util.concurrent.atomic.DoubleAdder;
public class GFG {
public static void main(String args[])
{
DoubleAdder num = new DoubleAdder();
// add operation on num
num.add(42);
num.add(10);
// sum operation on num
num.sum();
// Print after sum operation
System.out.println(" the value after sum() is: " + num);
// toString operation on variable num
num.toString();
// Print after toString operation
System.out.println("the value after toString() is: " + num);
}
}
輸出:
the value after sum() is: 52.0 the value after toString() is: 52.0
程序2:
// Program to demonstrate the toString() method
import java.lang.*;
import java.util.concurrent.atomic.DoubleAdder;
public class GFG {
public static void main(String args[])
{
DoubleAdder num = new DoubleAdder();
// add operation on num
num.add(402);
// sum operation on num
num.sum();
// Print after sum operation
System.out.println(" the value after sum() is: " + num);
// toString operation on variable num
num.toString();
// Print after toString operation
System.out.println("the value after toString() is: " + num);
}
}
輸出:
the value after sum() is: 402.0 the value after toString() is: 402.0
參考: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/DoubleAdder.html#toString–
相關用法
- Java DoubleAdder sum()用法及代碼示例
- Java DoubleAdder add()用法及代碼示例
- Java DoubleAdder doubleValue()用法及代碼示例
- Java DoubleAdder intValue()用法及代碼示例
- Java DoubleAdder reset()用法及代碼示例
- Java DoubleAdder sumThenReset()用法及代碼示例
- Java DoubleAdder floatValue()用法及代碼示例
- Java DoubleAdder longValue()用法及代碼示例
- Java Throwable toString()用法及代碼示例
- Java ZoneOffset toString()用法及代碼示例
- Java Package toString()用法及代碼示例
- Java String toString()用法及代碼示例
- Java LocalDateTime toString()用法及代碼示例
- Java BitSet toString()用法及代碼示例
- Java DigestInputStream.toString()用法及代碼示例
注:本文由純淨天空篩選整理自Twinkl Bajaj大神的英文原創作品 DoubleAdder toString() method in Java with Examples。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。