java tutorial - Java toString () method - java programming - learn java - java basics - java for beginners



Java numbers to string

Learn Java - Java tutorial - Java numbers to string - Java examples - Java programs

Description

  • The toString () method is used in Java to obtain a string object representing the value of a numeric object, in other words, it converts a number to a string.
  • If the method takes a simple data type as an argument, object that represents the value of a simple data type.
  • If the toString () method in Java takes two arguments, the string representation of the initial argument in the number system on the integer base identified by the next argument will be returned.

Syntax

The whole variant of the method is given below:

String toString()
static String toString(int i)
click below button to copy the code. By - java tutorial - team

Options

Detailed information about the parameters:

  • i - int, which will be changed and returned as string object (String).

Return value

  • toString (): Returns a string object representive the value of this integer.
  • toString (int i): returns a string object representive the identified integer.

Sample Code

public class Test { 

   public static void main(String args[]) {
      Integer y = 5;

      System.out.println(x.toString() );  // Convert y to string
      System.out.println(Integer.toString(12) );  // Convert int to string
   }
}
click below button to copy the code. By - java tutorial - team

Output

5
12

Related Searches to Java toString() method