

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Integer toString() in Java
The toString() method of the java.lang.Integer returns a string object. The Integer class has three toString() methods. Let us see them one by one −
String toString()
Example
The java.lang.Integer.toString() method returns a String object representing this Integer's value. Let us now see an example −
import java.lang.*; public class Demo { public static void main(String[] args) { Integer i = new Integer(20); // returns a string representation of the integer value in base 10 String retval = i.toString(); System.out.println("Value = " + retval); } }
Output
Value = 20
static String toString(int i)
The java.lang.Integer.toString(int i) method returns a String object representing the specified integer. Here, i is the integer to be converted.
Example
Let us now see an example −
import java.lang.*; public class Demo { public static void main(String[] args) { Integer i = new Integer(10); // returns a string representation of the specified integer in base 10 String retval = i.toString(30); System.out.println("Value = " + retval); } }
Output
Value = 30
static String toString(int i, int radix)
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.
Here, i is the integer to be converted, whereas radix is the radix to be used in the string representation.
Example
Let us now see an example −
import java.lang.*; public class Demo { 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); } }
Output
Value = 30 Value = 1e Value = 36
- Related Questions & Answers
- Java toString() method.
- Java Signature toString() method
- ShortBuffer toString() method in Java
- Provider toString() method in Java
- Duration toString() method in Java
- MonthDay toString() Method in Java
- Instant toString() method in Java
- LocalDate toString() method in Java
- LocalDateTime toString() method in Java
- LocalTime toString() method in Java
- StringJoiner toString() method in Java 8
- The toString() method of CopyOnWriteArrayList in Java
- Pattern toString() method in Java with examples
- Matcher toString() method in Java with Examples
- Java sql.Timestamp toString() method with example