Java int to string example using Integer.toString()
The Integer.toString() method is used to convert int to string in java. It takes an integer value as an argument and returns a string representing of it.
Example:
packagecom.w3spoint;publicclass IntToString {publicstaticvoid main(String args[]){int num =123;String str =Integer.toString(num);System.out.println("String is: "+str);}}
package com.w3spoint;
public class IntToString {
public static void main(String args[]){
int num = 123;
String str = Integer.toString(num);
System.out.println("String is: "+str);
}
}
The String.valueOf() method is used to convert int to string in java. It takes an integer value as an argument and returns a string representing of it.
Example:
packagecom.w3spoint;publicclass IntToString {publicstaticvoid main(String args[]){int num =123;String str =String.valueOf(num);System.out.println("String is: "+str);}}
package com.w3spoint;
public class IntToString {
public static void main(String args[]){
int num = 123;
String str = String.valueOf(num);
System.out.println("String is: "+str);
}
}