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 :


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) {
		// 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:

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