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
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
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework