Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Java toString() Method

Java toString() Method

Java String ClassJava String class


The toString() method returns this object itself (it is already a string).

Syntax


public String toString()

Parameters

Return Value

The string itself.

Example


public class Test {
    public static void main(String args[]) {
        String Str = new String("WWW.RUNOOB.COM");

        System.out.print("返回值 :" );
        System.out.println( Str.toString() );
    }
}

The execution result of the above program is:

返回值 :WWW.RUNOOB.COM

Java String ClassJava String class