LongAdder longValue() method in Java with Examples Last Updated : 28 Jan, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report 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() Parameters: The function does not accepts any parameter. Return Value: This method returns a long value which is the current sum. Below programs demonstrate the above function: Program 1: Java // Java program to demonstrate // the LongAdder.longValue() 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); // longValue operation on num num.longValue(); // Print after sum System.out.println("Returned longValue is: " + num); } } Output: Initial value is: 0 After addition of 6, value is: 6 After addition of 5, value is: 11 Returned longValue is: 11 Program 2: Java // Java program to demonstrate // the LongAdder.longValue() 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 100 to it num.add(100); // Print the final value System.out.println("After addition" + " of 100, value is: " + num); // longValue operation on num num.longValue(); // Print after sum System.out.println("Returned longValue is: " + num); } } Output: Initial value is: 0 After addition of 10, value is: 10 After addition of 100, value is: 110 Returned longValue is: 110 Comment More infoAdvertise with us Next Article Short longValue() method in Java with Example T Twinkl Bajaj Follow Improve Article Tags : Misc Java Java - util package Java-Functions Java-LongAdder +1 More Practice Tags : JavaMisc Similar Reads LongAccumulator longValue() method in Java with Examples The java.LongAccumulator.longValue() is an inbuilt method in java that is equivalent to the get() method that is this method just returns the current value. Syntax: public long longValue() Parameters: This method does not accepts any parameter. Return Value: The method returns the current value. Bel 1 min read Byte longValue() method in Java with examples The longValue() method of Byte class is a built in method in Java which is used to return the value of this Byte object as long. Syntax ByteObject.longValue() Return Value: It return the value of ByteObject as long. Below is the implementation of longValue() method in Java: Example 1: Java // Java c 2 min read LongAdder add() method in Java with Examples 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 meth 2 min read Number.longValue() method in java with examples The Number.longValue() is an inbuilt method in Java of java.lang package. This method is used to convert any numeric value into a long type. This may involve rounding or truncation.What is longValue()?The longValue() method returns the value of a number after converting it to the long data type. Som 2 min read Short longValue() method in Java with Example The java.lang.Short.longValue() method of Short class is a built in method in Java which is used to return the value of the Short object as a long. Syntax ShortObject.longValue() Return Value: It return the value of ShortObject as long. Below is the implementation of longValue() method in Java: Exam 2 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 Like