Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
DoubleAdder reset() method in Java with Examples
Next article icon

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-

Next Article
DoubleAdder reset() method in Java with Examples

T

Twinkl Bajaj
Improve
Article Tags :
  • Misc
  • Java
  • Java-Functions
  • Java-DoubleAdder
Practice Tags :
  • Java
  • Misc

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
  • DoubleAdder reset() method in Java with Examples
    The java.DoubleAdder.reset() is an inbuilt method in java that resets variables maintaining the sum to zero. When the object of the class is created its initial value is zero. Syntax: public void reset() Parameters: This method does not accepts any parameter. Return Value: The method returns the res
    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
  • Double doubleValue() method in Java with examples
    The doubleValue() method of Double class is a built in method to return the value specified by the calling object as double after type casting. Syntax: DoubleObject.doubleValue() Return Value: It return the value of DoubleObject as double. Below programs illustrate doubleValue() method in Java: Prog
    2 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
  • DelayQueue add() method in Java with Examples
    The add(E ele) method of DelayQueue class in Java is used to insert the given element into the delay queue and returns true if the element has been successfully inserted. Here, E refers to the type of elements maintained by this DelayQueue collection.Syntax: public boolean add(E ele) Parameters: Thi
    2 min read
  • BigInteger add() Method in Java with Examples
    The java.math.BigInteger.add(BigInteger val) is used to calculate the Arithmetic sum of two BigIntegers. This method is used to find arithmetic addition of large numbers of range much greater than the range of biggest data type double of java without compromising with the precision of the result. Th
    3 min read
  • DoubleAdder longValue() method in Java with Examples
    The java.DoubleAdder.longValue() is an inbuilt method in java that returns the sum() as a long after a narrowing primitive conversion. When the object of the class is created its initial value is zero. Syntax: public long longValue() Parameters:Return value: This method returns the numeric value rep
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences