DoubleAccumulator reset() method in Java with Examples

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

DoubleAccumulator before reset: 12.0
DoubleAccumulator after reset: 0.0

Program 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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);
    }
}

chevron_right


Output:

DoubleAccumulator before reset: 62.0
DoubleAccumulator after reset: 0.0


My Personal Notes arrow_drop_up

Contented with little yet wishing for more

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.