1. Converting Integer to String in Java using Integer.toString(int)
int x = 500;
String str = Integer.toString(n);
System.out.println("The output string is: " + str);
Output
The output string is: 500
2. Converting Integer to String in Java using String.valueOf(int)
int y = 555;
String str = String.valueOf(number);
System.out.println("The output string is: " + str);
Output
The output string is: 555
3. Converting Integer to String in Java using String.format()
int number = 505;
String str = String.format("%d", number);
System.out.println("The output string is: " + str);
Output
The output string is: 505
4. Converting Integer to String in Java using DecimalFormat
import java.text.DecimalFormat;
...
int oneMillion = 1000000;
DecimalFormat numberFormat = new DecimalFormat("##,###");
String str = numberFormat.format(oneMillion);
System.out.println("Before: " + oneMillion);
System.out.println("After: " + str);
Output
Before: 1000000
After: 1,000,000
5. Converting Integer to String in Java using StringBuilder
int x = 500500;
StringBuilder sb = new StringBuilder();
sb.append(x);
String str = sb.toString();
System.out.println("Converting int to String using StringBuilder: " + str);
Output
Converting int to String using StringBuilder: 500500
6. Converting Integer to String in Java using StringBuilder
int y = 500500;
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(y);
String str = stringBuffer.toString();
System.out.println("Converting int to String using StringBuffer: " + str);
Output
Converting int to String using StringBuffer: 500500