Java String: toString() Method

public String toString()

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

Java Platform: Java SE 8



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) {
		// 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
		Integer myValue = new Integer(intValue);
		String value = myValue.toString();
		out.println("String Value is " + value);



Input Desired Value:125
String Value is 125 

Java Code Editor:

Previous:toLowerCase Method
Next:toUpperCase Method

Follow us on Facebook and Twitter for latest update.