- Java.lang Package classes
- Java.lang - Home
- Java.lang - Boolean
- Java.lang - Byte
- Java.lang - Character
- Java.lang - Character.Subset
- Java.lang - Character.UnicodeBlock
- Java.lang - Class
- Java.lang - ClassLoader
- Java.lang - Compiler
- Java.lang - Double
- Java.lang - Enum
- Java.lang - Float
- Java.lang - InheritableThreadLocal
- Java.lang - Integer
- Java.lang - Long
- Java.lang - Math
- Java.lang - Number
- Java.lang - Object
- Java.lang - Package
- Java.lang - Process
- Java.lang - ProcessBuilder
- Java.lang - Runtime
- Java.lang - RuntimePermission
- Java.lang - SecurityManager
- Java.lang - Short
- Java.lang - StackTraceElement
- Java.lang - StrictMath
- Java.lang - String
- Java.lang - StringBuffer
- Java.lang - StringBuilder
- Java.lang - System
- Java.lang - Thread
- Java.lang - ThreadGroup
- Java.lang - ThreadLocal
- Java.lang - Throwable
- Java.lang - Void
- Java.lang Package extras
- Java.lang - Interfaces
- Java.lang - Errors
- Java.lang - Exceptions
- Java.lang Package Useful Resources
- Java.lang - Useful Resources
- Java.lang - Discussion
Java - Integer toString(int i, int radix) method
Description
The Java 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
Getting String Representation of a Positive int Value in Decimal Format Example
The following example shows the usage of Integer toString(int i, int radix) method to get the decimal string representation of the specified int value. We've created a int variable and assigned it a positive int value. Then using toString() method, we're printing the result.
package com.tutorialspoint; public class IntegerDemo { public static void main(String[] args) { int i = 170; System.out.println("Number = " + i); /* returns the decimal string representation of the given number */ System.out.println("toString = " + Integer.toString(i,10)); } }
Output
Let us compile and run the above program, this will produce the following result −
Number = 170 toString = 170
Getting String Representation of a Positive int Value in Octal Format Example
The following example shows the usage of Integer toString(int i, int radix) method to get the octal string representation of the specified int value. We've created a int variable and assigned it a positive int value. Then using toString() method, we're printing the result.
package com.tutorialspoint; public class IntegerDemo { public static void main(String[] args) { int i = 170; System.out.println("Number = " + i); /* returns the octal string representation of the given number */ System.out.println("toString = " + Integer.toString(i,8)); } }
Output
Let us compile and run the above program, this will produce the following result −
Number = 170 toString = 252
Getting String Representation of a Positive int Value in HexaDecimal Format Example
The following example shows the usage of Integer toString(int i, int radix) method to get the hexadecimal string representation of the specified int value. We've created a int variable and assigned it a positive int value. Then using toString() method, we're printing the result.
package com.tutorialspoint; public class IntegerDemo { public static void main(String[] args) { int i = 170; System.out.println("Number = " + i); /* returns the hexadecimal string representation of the given number */ System.out.println("toString = " + Integer.toString(i,16)); } }
Output
Let us compile and run the above program, this will produce the following result −
Number = 170 toString = aa
Getting String Representation of a Positive int Value in Binary Format Example
The following example shows the usage of Integer toString(int i, int radix) method to get the binary string representation of the specified int value. We've created a int variable and assigned it a positive int value. Then using toString() method, we're printing the result.
package com.tutorialspoint; public class IntegerDemo { public static void main(String[] args) { int i = 170; System.out.println("Number = " + i); /* returns the binary string representation of the given number */ System.out.println("toString = " + Integer.toString(i,2)); } }
Output
Let us compile and run the above program, this will produce the following result −
Number = 170 toString = 10101010
To Continue Learning Please Login
Login with Google