w3resource logo


Introduction to Java Programming

Java String: toString() Method

Secondary Nav

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

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:







Join our Question Answer community to learn and share your programming knowledge.

Help the community:

PHP: Loop

JavaScript: Delete duplicates in an array

Oracle: Round the number