w3resource

Java String: toString() Method

public String toString()

This object (which is already a string!) is itself returned.

Java Platform: Java SE 8

Syntax:

toString()

Return Value: the string itself.

Return Value Type: String

Pictorial presentation of Java String toString() Method

Java String: toString() Method

Example: Java String toString() Method

The following example shows the usage of java String() method.

import java.util.Scanner;
import static java.lang.System.*;
public class IntegerToString {

	public static void main(String[] args) {
	    System.out.println();
		// Ask user input
		System.out.print("Input Desired Value:");
		// declare the scanner object
		Scanner scan = new Scanner(System.in);
		// use scanner to get the value from user console
		int intValue = scan.nextInt();
		// close the scanner object
		scan.close();
		Integer myValue = new Integer(intValue);
		String value = myValue.toString();
		out.println("String Value is " + value);
        System.out.println();
	}

}

Output:

Input Desired Value:125
String Value is 125 

Java Code Editor:

Previous:toLowerCase Method
Next:toUpperCase Method



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://www.w3resource.com/java-tutorial/string/string_tostring.php