OptionalInt toString() method in Java with examples Last Updated : 28 May, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The toString() method help us to get a non-empty string representation of this OptionalInt.This non-empty string representation is suitable for debugging. The exact presentation format is unspecified and may vary between implementations and versions. Syntax: public String toString() Parameters: This method accepts nothing. Return value: This method returns the string representation of this instance. Below programs illustrate toString() method: Program 1: Java // Java program to demonstrate // OptionalInt.toString() method import java.util.OptionalInt; public class GFG { public static void main(String[] args) { // create a OptionalInt OptionalInt opInt = OptionalInt.of(452146); // get value using toString String value = opInt.toString(); // print value System.out.println("String Representation: " + value); } } Output: String Representation: OptionalInt[452146] Program 2: Java // Java program to demonstrate // OptionalInt.toString() method import java.util.OptionalInt; public class GFG { public static void main(String[] args) { // create a OptionalInt OptionalInt opInt = OptionalInt.empty(); // get value using toString String value = opInt.toString(); // print value System.out.println("String Representation: " + value); } } Output: String Representation: OptionalInt.empty References: https://docs.oracle.com/javase/10/docs/api/java/util/OptionalInt.html#toString() Comment More infoAdvertise with us Next Article OptionalLong toString() method in Java with examples A AmanSingh2210 Follow Improve Article Tags : Java Java - util package Java-Functions Java-OptionalInt Practice Tags : Java Similar Reads Optional toString() method in Java with examples The toString() method of java.util.Optional class in Java is used to get the string representation of this Optional instance. Syntax: public String toString() Parameters: This method accepts nothing. Return value: This method returns the string representation of this Optional instance. Below program 1 min read OptionalLong toString() method in Java with examples The toString() method help us to get a non-empty string representation of this OptionalLong.This non-empty string representation is suitable for debugging. The exact presentation format is unspecified and may vary between implementations and versions. Syntax: public String toString() Parameters: Thi 1 min read OptionalDouble toString() method in Java with examples The toString() method help us to get a non-empty string representation of this OptionalDouble.This non-empty string representation is suitable for debugging. The exact presentation format is unspecified and may vary between implementations and versions. Syntax: public String toString() Parameters: T 1 min read Optional or() method in Java with examples The or() method of java.util.Optional class in Java is used to get this Optional instance if any value is present. If there is no value present in this Optional instance, then this method returns an Optional instance with the value generated from the specified supplier. Syntax: public Optional<T 2 min read OptionalInt orElseGet() method in Java with examples The orElseGet(java.util.function.IntSupplier) method helps us to get the value in this OptionalInt object. If a value is not present in this OptionalInt, then this method returns the result produced by the supplying function, passed as the parameter Syntax: public int orElseGet(IntSupplier supplier) 2 min read String toString() Method in java with Examples String toString() is the built-in method of java.lang which return itself a string. So here no actual conversion is performed. Since toString() method simply returns the current string without any changes, there is no need to call the string explicitly, it is usually called implicitly. Syntax : publ 1 min read Like