LongAdder add() method in Java with Examples Last Updated : 28 Jan, 2019 Comments Improve Suggest changes Like Article Like Report LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.add() is an inbuilt method in java that adds the given value. Syntax: public void add(long x) Parameters: The function accepts a single parameter x that specifies the value to be added. Return value: The method do not returns any value. Below programs demonstrate the above function: Program 1: Java // Java program to demonstrate // the LongAdder.add() method import java.lang.*; import java.util.concurrent.atomic.LongAdder; public class GFG { public static void main(String args[]) { // Initialized with 0 LongAdder num = new LongAdder(); // Print the initial value System.out.println("Initial value is: " + num); // Add 6 to it num.add(6); // Print the final value System.out.println("After addition" + " of 6, value is: " + num); // Add 5 to it num.add(5); // Print the final value System.out.println("After addition" + " of 5, value is: " + num); } } Output: Initial value is: 0 After addition of 6, value is: 6 After addition of 5, value is: 11 Program 2: Java // Java program to demonstrate // the LongAdder.add() method import java.lang.*; import java.util.concurrent.atomic.LongAdder; public class GFG { public static void main(String args[]) { // Initialized with 0 LongAdder num = new LongAdder(); // Print the initial value System.out.println("Initial value is: " + num); // Add 10 to it num.add(10); // Print the final value System.out.println("After addition" + " of 10, value is: " + num); // Add -5 to it num.add(-5); // Print the final value System.out.println("After addition" + " of -5, value is: " + num); } } Output: Initial value is: 0 After addition of 10, value is: 10 After addition of -5, value is: 5 Comment More infoAdvertise with us Next Article LongAdder add() method in Java with Examples T Twinkl Bajaj Follow Improve Article Tags : Misc Java Java - util package Java-Functions Java-LongAdder +1 More Practice Tags : JavaMisc Similar Reads LongAdder sum() method in Java with Examples LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.sum() is an inbuilt method in java that returns the sum. Syntax: public long sum() Parameters: The function does not accepts any parameter. Return value: The method returns the current sum. Program below demo 2 min read LongAdder decrement() method in Java with Examples LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.decrement() is an inbuilt method in java that reduces the value by 1. Syntax: public void decrement() Parameters: The function does not accepts any parameter. Return value: The method do not returns any value 2 min read LongAdder reset() method in Java with Examples LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.reset() is an inbuilt method in Java that resets the sum to zero. When the object of the class is created its initial value is zero. Syntax: public void reset() Parameters: The function does not accepts any p 2 min read LongAdder doubleValue() method in Java with Examples LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.doubleValue() is an inbuilt method in java that returns the sum as a double value. When the object of the class is created its initial value is zero. Syntax: public double doubleValue() Parameters: The functi 2 min read List add() Method in Java with Examples The List add() method adds (appends) an element to a list. It can be used for both ArrayList and LinkedList. Example of List add() Method: Java // Java program to demonstrate // ArrayList usage import java.io.*; import java.util.ArrayList; import java.util.List; class GFG { public static void main ( 3 min read LongAdder toString() method in Java with Examples LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.toString() is an inbuilt method in Java that returns the String representation of this LongAdder. When the object of the class is created its initial value is zero. Syntax: public String toString() Parameters 2 min read LongAdder intValue() method in Java with Examples LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.intValue() is an inbuilt method in java that returns the sum as a int value. When the object of the class is created its initial value is zero. Syntax: public int intValue() Parameters: The function does not 2 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 LongAdder increment() method in Java with Examples LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.increment() is an inbuilt method in java that increases the value by 1. Syntax: public void increment() Parameters: The function does not accepts any parameter. Return value: The method do not returns any val 2 min read LongAdder longValue() method in Java with Examples LongAdder class in Java creates a new adder with an initial sum of zero. The Java.LongAdder.longValue() is an inbuilt method in java that returns the sum(). This method is equivalent to the sum() method. When the object of the class is created its initial value is zero. Syntax: public long longValue 2 min read Like