DoubleAdder sumThenReset() method in Java with Examples Last Updated : 28 Jan, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 sumThenReset() Parameters: This method does not accepts any parameter. Return Value: The method returns the sum. Below programs illustrate the above method: Program 1: Java // Program to demonstrate the sumThenReset() 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); // sumThenReset operation on variable num num.sumThenReset(); // Print after sumThenReset operation System.out.println("the current value is: " + num); } } Output: the value after sum is: 52.0 the current value is: 0.0 Program 2: Java // Program to demonstrate the sumThenReset() 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(254); // sum operation on num num.sum(); // Print after sum operation System.out.println(" the value after sum is: " + num); // sumThenReset operation on variable num num.sumThenReset(); // Print after sumThenReset operation System.out.println("the current value is: " + num); } } Output: the value after sum is: 254.0 the current value is: 0.0 Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/DoubleAdder.html#sumThenReset-- Comment More infoAdvertise with us Next Article LongAdder sumThenReset() method in Java with Examples T Twinkl Bajaj Follow Improve Article Tags : Misc Java Java-Functions Java-DoubleAdder Practice Tags : JavaMisc Similar Reads DoubleAdder sum() method in Java with Examples 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 progra 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 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 LongAdder sumThenReset() method in Java with Examples LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.sumThenReset() is an inbuilt method in Java that is equivalent to sum() then reset() function. Firstly, the sum is calculated and then it is reset to the value 0. When the object of the class is created its i 2 min read DoubleAdder intValue() method in Java with Examples The java.DoubleAdder.intValue() is an inbuilt method in java that returns the sum() as an int after a narrowing primitive conversion. When the object of the class is created its initial value is zero. Syntax: public int intValue() Parameters: This method does not accepts any parameter. Return Value: 1 min read DoubleAdder longValue() method in Java with Examples The java.DoubleAdder.longValue() is an inbuilt method in java that returns the sum() as a long after a narrowing primitive conversion. When the object of the class is created its initial value is zero. Syntax: public long longValue() Parameters:Return value: This method returns the numeric value rep 1 min read Like