Convert int to String
In this chapter you will learn:
Convert integer to string
Converting int type value to string can be done through the following methods.
String toString()
returns a String object representing this Integer's value.static String toString(int i)
returns a String object representing the specified integer.static String toString(int i, int radix)
returns a string representation of the first argument in the radix specified by the second argument.
Integer.toString
is usually the choice.
public class Main {
public static void main(String[] args) {
//from j a va 2 s . c om
System.out.println(Integer.toString(10));
}
}
The output:
To indicate the radix during converting integer to string:
public class Main {
public static void main(String[] args) {
/*from ja va 2 s .com*/
System.out.println(Integer.toString(10, 8));
}
}
The output:
Next chapter...
What you will learn in the next chapter:
- How to reverse and rotate the integer in binary format
- How to bit oriented operation on int type value
- How to get the leading and trailing zeros
Home » Java Tutorial » Primitive Data Types