LongAdder toString() 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.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: The function does not accepts any parameter. Return value: The method returns a String value which is the String representation of this LongAdder. Below programs demonstrate the above function: Program 1: Java // Java program to demonstrate // the LongAdder.toString() 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); // toString operation on num System.out.println("String representation" + " of the LongAdder: " + num.toString()); } } Output: Initial value is: 0 After addition of 6, value is: 6 After addition of 5, value is: 11 String representation of the LongAdder: 11 Program 2: Java // Java program to demonstrate // the LongAdder.toString() 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); // toString operation on num System.out.println("String representation" + " of the LongAdder: " + num.toString()); } } Output: Initial value is: 0 After addition of 10, value is: 10 After addition of 100, value is: 110 String representation of the LongAdder: 110 Comment More infoAdvertise with us Next Article Matcher toString() 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 Locale toString() Method in Java with Examples The toString() method of Locale class in Java is used to return a string representation of this locale. Each element i.e., the language, country or the variant of the locale is separated by underbars Syntax: LOCALE.toString() Parameters: This method does not take any parameters. Return Value: This m 1 min read Level toString() method in Java with Examples The toString() method of java.util.logging.Level is used to get the string value which represents this Level.This method returns a string representation of this Level. Syntax: public String toString() Parameters: This method accepts nothing. Return: This method returns a string representation of thi 1 min read Matcher toString() method in Java with Examples The toString() method of Matcher Class is used to get the String representation of this matcher. This method is derived from the Object Class and behaves in the similar way. Syntax: public String toString() Parameters: This method takes no parameters. Return Value: This method returns a String value 2 min read LongAccumulator toString() method in Java with Examples The java.LongAccumulator.toString() is an inbuilt method in java that returns the String representation of the current value of the LongAccumulator instance. Syntax: public String toString() Parameters: This method does not accepts any parameter. Return Value: This method returns the string represen 2 min read MessageDigest toString() method in Java with Examples The toString() method of java.security.MessageDigest class is used to provide the object of message digest in string format. Syntax: public String toString() Return Value: This method returns the object of message digest in string format. Below are the examples to illustrate the toString() method: E 2 min read Byte toString() method in Java with examples The toString() method of Byte class is a built in method in Java which is used to return a String value. public String toString() Syntax: ByteObject.toString() Return Value: It returns a String object, the value of which is equal to the value of the ByteObject. Below is the implementation of toStrin 2 min read Like