Facebook Page Twitter Page LinkedIn Page
× Java Tutorial Java Advanced Java Resources


The Java string toString() method is used to return 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 below example, toString() method to used to return 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