Class toString() method in Java with Examples Last Updated : 27 Nov, 2019 Comments Improve Suggest changes Like Article Like Report The toString() method of java.lang.Class class is used to convert the instance of this Class to a string representation. This method returns the formed string representation. Syntax: public String toString() Parameter: This method does not accept any parameter. Return Value: This method returns the String representation of this object. Below programs demonstrate the toString() method. Example 1: Java // Java program to demonstrate toString() method public class Test { public static void main(String[] args) throws ClassNotFoundException { // returns the Class object for the class // with the specified name Class c1 = Class.forName("java.lang.String"); System.out.print("Class represented by c1: "); // toString method on c1 System.out.println(c1.toString()); } } Output: Class represented by c1: class java.lang.String Example 2: Java // Java program to demonstrate toString() method public class Test { public static void main(String[] args) throws ClassNotFoundException { // returns the Class object for the class // with the specified name Class c2 = int.class; Class c3 = void.class; System.out.print("Class represented by c2: "); // toString method on c2 System.out.println(c2.toString()); System.out.print("Class represented by c3: "); // toString method on c3 System.out.println(c3.toString()); } } Output: Class represented by c2: int Class represented by c3: void Reference: https://docs.oracle.com/javase/9/docs/api/java/lang/Class.html#toString-- Comment More infoAdvertise with us Next Article Class toString() method in Java with Examples S srinam Follow Improve Article Tags : Java Java-lang package Java-Functions Java.lang.Class Practice Tags : Java Similar Reads Class toGenericString() method in Java with Examples The toGenericString() method of java.lang.Class class is used to convert the instance of this Class to a string representation along with the information about the modifiers and type parameters. This method returns the formed string representation. Syntax: public String toGenericString() Parameter: 2 min read Calendar toString() Method in Java with Examples The toString() method in Calendar class is used to get the string representation of the Calendar object. This method in Calendar Class is just for debug process and not to be used as an operation. Syntax: public String toString() Parameters: The method does not take any parameters. Return Value: The 1 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 Bidi toString() method in Java with Examples The toString() method of java.text.Bidi class is used to display this Bidi instance in string representation. Syntax: public String toString() Parameter: This method accepts nothing as parameter. Return Value: This method display internal state of bidi in string format. Below are the examples to ill 2 min read Duration toString() method in Java with Examples The toString() method of Duration Class in java.time package is used to get the String value of this duration. This String is in the ISO-8601 format. Syntax: public String toString() Parameters: This method do not accepts any parameter. Return Value: This method returns a String value which is the S 1 min read Like