Java.lang.Integer.toString() Method

Advertisements


Description

The java.lang.Integer.toString(int i, int radix) method returns a string representation of the first argument i in the radix specified by the second argument radix.If the radix is smaller than Character.MIN_RADIX or larger than Character.MAX_RADIX, then the radix 10 is used instead.

The following ASCII characters are used as digits: 0123456789abcdefghijklmnopqrstuvwxyz

Declaration

Following is the declaration for java.lang.Integer.toString() method

public static String toString(int i, int radix)

Parameters

  • i -- This is an integer to be converted.

  • radix -- This is the radix to use in the string representation.

Return Value

This method returns a string representation of the argument in the specified radix.

Exception

  • NA

Example

The following example shows the usage of java.lang.Integer.toString() method.

package com.tutorialspoint;

import java.lang.*;

public class IntegerDemo {

   public static void main(String[] args) {

     Integer i = new Integer(10);
   
     // returns a string representation of the specified integer with radix 10
     String retval = i.toString(30, 10);
     System.out.println("Value = " + retval);
     
     // returns a string representation of the specified integer with radix 16
     retval = i.toString(30, 16);
     System.out.println("Value = " + retval);
     
     // returns a string representation of the specified integer with radix 8
     retval = i.toString(30, 8);
     System.out.println("Value = " + retval);
   }
} 

Let us compile and run the above program, this will produce the following result:

Value = 30
Value = 1e
Value = 36



Advertisements
Advertisements