DoubleAdder sum() method in Java with Examples Last Updated : 28 Jan, 2019 Comments Improve Suggest changes Like Article Like Report The java.DoubleAdder.sum() is an inbuilt method in java that returns the current sum. When the object of the class is created its initial value is zero. Syntax: public double sum() Parameters: This method does not accepts any parameter. Return Value: This method returns the current sum. Below programs illustrate the above method: Program 1: Java // Program to demonstrate the sum() 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 variable num num.sum(); // Print after add operation System.out.println(" the current value is: " + num); } } Output: the current value is: 52.0 Program 2: Java // Program to demonstrate the sum() 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(10); // sum operation on variable num num.sum(); // Print after add operation System.out.println(" the current value is: " + num); } } Output: the current value is: 10.0 Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/DoubleAdder.html#sum-- Comment More infoAdvertise with us Next Article DoubleAdder sum() method in Java with Examples T Twinkl Bajaj Follow Improve Article Tags : Misc Java Java-Functions Java-DoubleAdder Practice Tags : JavaMisc Similar Reads DoubleAdder sumThenReset() method in Java with Examples The java.DoubleAdder.sumThenReset() is an inbuilt method in java is equivalent to sum() then reset() method that is firstly the effective sum is calculated and then the value is reset to maintain the value zero. When the object of the class is created its initial value is zero. Syntax: public double 2 min read DoubleAdder add() method in Java with Examples The java.DoubleAdder.add() is an inbuilt method in java that adds the given value to the previous or initial value. When the object of the class is created its initial value is zero. Syntax: public void add(double x) Parameters: This method accepts a single parameter x that specifies the value to be 1 min read DoubleAdder toString() method in Java with Examples The java.DoubleAdder.toString() is an inbuilt method in java that returns the String representation of the sum() method. When the object of the class is created its initial value is zero. Syntax: public String toString() Parameters: This method does not accepts any parameter. Return Value: The metho 2 min read Number.doubleValue() method in java with examples The Number.doubleValue() is an inbuilt method in Java from java.lang.Number package. This method returns the value of the specified number cast as a double data type. This may involve rounding or truncation.Syntax of doubleValue() Methodpublic abstract double doubleValue()Parameters: This method doe 3 min read Short doubleValue() method in Java with Examples The java.lang.Short.doubleValue() method of Short class is a built in method in Java which is used to return the value of the Short object as a double. Syntax: public double doubleValue() Return type: It return the value of ShortObject as double. Below is the implementation of doubleValue() method i 2 min read Like