Java Integer - toString() Method
The java.lang.Integer.toString() method returns a String object representing this Integer's value. The value is converted to signed decimal representation and returned as a string, exactly as if the integer value were given as an argument to the toString(int) method.
Syntax
public String toString()
Parameters
No parameter is required.
Return Value
Returns a string representation of the value of this object in base 10.
Exception
NA.
Example:
In the example below, the java.lang.Integer.toString() method returns a String object representing the given Integer's value.
import java.lang.*; public class MyClass { public static void main(String[] args) { //creating Integer object Integer x = 25; //printing the Integer object System.out.println("The Integer object is: " + x); //creating and printing the string representation //of the Integer object's value String x_tostring = x.toString(); System.out.println("The string value of Integer is: " + x_tostring); } }
The output of the above code will be:
The Integer object is: 25 The string value of Integer is: 25
❮ Java.lang - Integer