Java.lang Package Classes

Java Integer - toString() Method



The java.lang.Integer.toString() method returns a String object representing the specified integer. The argument is converted to signed decimal representation and returned as a string, exactly as if the argument and radix 10 were given as arguments to the toString(int, int) method.

Syntax

public static String toString(int i)

Parameters

i Specify the integer to be converted.

Return Value

Returns a string representation of the argument in base 10.

Exception

NA.

Example:

In the example below, the java.lang.Integer.toString() method returns a String object representing the given integer.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    
    //creating a int value
    int x = 25;

    //printing the int value 
    System.out.println("The int value is: " + x); 

    //creating and printing the string 
    //representation of the int value
    String x_tostring = Integer.toString(x);
    System.out.println("The string value of integer is: " + x_tostring);   
  }
}

The output of the above code will be:

The int value is: 25
The string value of integer is: 25

❮ Java.lang - Integer