Java Integer toString() method
The toString() method of Java Integer class returns a String object which represents this Integer’s value. The second syntax returns a String object which represents the specified integer. The third syntax returns a string representation of the specified argument in the radix specified by the given radix. Syntax
- public String toString ()
- public static String toString (int i)
- public static String toString (int i, int radix)
public class JavaIntegerToStringExample1 { public static void main(String[] args) { Integer val=5667; String val1=Integer.toString(val); //It returns a string representation of the value of this object in base 10. System.out.println("String Value : "+val1); } }Output
String Value : 5667Example 2
public class JavaIntegerToStringExample2 { public static void main(String[] args) { Integer val=Integer.MAX_VALUE; String val1=val.toString(); //It returns a string representation of the value of this object in base 10. System.out.println("String Value : "+val1); } }Output
String Value : 2147483647Example 3
public class JavaIntegerToStringExample3 { public static void main(String[] args) { Integer val=566787643; int radix=78; String val1=Integer.toString(val,radix); //It returns a string representation of the value of this object in the specified radix. System.out.println("String Value : "+val1); } }Output
String Value : 566787643Example 4
public class JavaIntegerToStringExample4 { public static void main(String[] args) { //passing negative value Integer val=-5667; String val1=Integer.toString(val); System.out.println("Unsigned String Value : "+val1); //calling string class methods StringBuffer sf= new StringBuffer(val1); StringBuffer reverse=sf.reverse(); System.out.println("Reverse of "+sf+" : "+reverse); } }Output
Unsigned String Value : -5667 Reverse of 7665- : 7665-