Skip to content
Related Articles

Related Articles

DoubleAccumulator reset() method in Java with Examples

Improve Article
Save Article
  • Last Updated : 29 Jan, 2019
Improve Article
Save Article

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:

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
Related Articles

Start Your Coding Journey Now!