Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

DoubleAccumulator reset() method in Java with Examples

  • Last Updated : 29 Jan, 2019

The Java.DoubleAccumulator.reset() is an inbuilt method in java that resets variables maintaining updates to the identity value. It means it only returns the reset value and does not takes any parameter. The return type is int.

Syntax:

Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.

public void reset()

Parameters: The method does not accepts any parameter.

Return Value: The method does not returns anything.



Below programs illustrate the above method:

Program 1:




// Java program to demonstrate
// the reset() method
  
import java.lang.*;
import java.util.concurrent.atomic.DoubleAccumulator;
  
public class GFG {
    public static void main(String args[])
    {
  
        DoubleAccumulator num
            = new DoubleAccumulator(
                Double::sum, 0L);
  
        // accumulate operation on num
        num.accumulate(2);
        num.accumulate(10);
  
        // Print before doubleValue operation
        System.out.println("DoubleAccumulator before reset: "
                           + num);
  
        // resets current value
        num.reset();
  
        // Print after reset operation
        System.out.println("DoubleAccumulator after reset: "
                           + num);
    }
}
Output:
DoubleAccumulator before reset: 12.0
DoubleAccumulator after reset: 0.0

Program 2:




// Java program to demonstrate
// the reset() method
  
import java.lang.*;
import java.util.concurrent.atomic.DoubleAccumulator;
  
public class GFG {
    public static void main(String args[])
    {
  
        DoubleAccumulator num
            = new DoubleAccumulator(
                Double::sum, 0L);
  
        // accumulate operation on num
        num.accumulate(45);
        num.accumulate(17);
  
        // Print before doubleValue operation
        System.out.println("DoubleAccumulator before reset: "
                           + num);
  
        // resets current value
        num.reset();
  
        // Print after reset operation
        System.out.println("DoubleAccumulator after reset: "
                           + num);
    }
}
Output:
DoubleAccumulator before reset: 62.0
DoubleAccumulator after reset: 0.0



My Personal Notes arrow_drop_up
Recommended Articles
Page :