DoubleAdder add() method in Java with Examples Last Updated : 28 Jan, 2019 Comments Improve Suggest changes Like Article Like Report 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 added. Return Value: The method returns the new value after the addition operation. Below programs illustrate the above function: Program 1: Java // Program to demonstrate the add() 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); // Print after add operation System.out.println(" the current value is: " + num); } } Output: the current value is: 52.0 Program 2: Java // Program to demonstrate the add() 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(1); // Print after add operation System.out.println(" the current value is: " + num); } } Output: the current value is: 1.0 Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/DoubleAdder.html#add-double- Comment More infoAdvertise with us Next Article DoubleAdder add() 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 Calendar add() Method in Java with Examples The add() method of Calendar class present inside is used to add or subtract from the given calendar field(int field), a specific amount of time(int amt), based on the calendar's rules. Syntax: public abstract void add(int field, int amt) Parameters: The method takes two parameters: The field of the 3 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 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 doubleValue() method in Java with Examples The java.DoubleAdder.doubleValue() is an inbuilt method in java that is equivalent to the method sum(), that is it returns current sum value. When the object of the class is created its initial value is zero. Syntax: public double doubleValue() Parameters: The method does not accepts any parameter. 1 min read Like