Java String - toString() Method
The Java toString() method returns the object (which is already a string!) itself.
Syntax
public String toString()
Parameters
No parameter is required.
Return Value
Returns the string itself.
Example:
In the example below, toString() method returns the string object itself.
public class MyClass { public static void main(String[] args) { String MyString = "Hello World"; String NewString = MyString.toString(); System.out.println(NewString); } }
The output of the above code will be:
Hello World
❮ Java String Methods