The Java.DoubleAccumulator.accumulate() method is an inbuilt method in Java that updates with the given value in this DoubleAccumulator instance. It means that it takes a double value as a parameter and adds it up to this instance of DoubleAccumulator on which it is called.
Syntax:
public void accumulate(double valueToBeAccumulated)
Parameters: This method accepts a single mandatory parameter valueToBeAccumulated which is the double value to be updated in the current instance of this DoubleAccumulator.
Return value: This method do not return any value. It just updates this DoubleAccumulator.
Program below demonstrates the function:
Program 1:
Java
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);
System.out.println("Current DoubleAccumulator"
+ " value is: "
+ num);
num.accumulate( 2 );
System.out.println("Updated DoubleAccumulator"
+ " value is: "
+ num);
}
}
|
Output:
Current DoubleAccumulator value is: 0.0
Updated DoubleAccumulator value is: 2.0
Program 2:
Java
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);
System.out.println("Current DoubleAccumulator"
+ " value is: "
+ num);
num.accumulate( 42.2 );
System.out.println("Updated DoubleAccumulator"
+ " value is: "
+ num);
}
}
|
Output:
Current DoubleAccumulator value is: 0.0
Updated DoubleAccumulator value is: 42.2
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
26 May, 2022
Like Article
Save Article