In Android development, you can convert an int
value to a String
using the toString()
method or by using one of the following methods:
String.valueOf()
:int num = 123; String str = String.valueOf(num);
Integer.toString()
:int num = 123; String str = Integer.toString(num);
String.format()
:int num = 123; String str = String.format("%d", num);
StringBuilder
:int num = 123; StringBuilder builder = new StringBuilder(); builder.append(num); String str = builder.toString();
String.format()
and Locale.US
:int num = 123; String str = String.format(Locale.US, "%d", num);
You can choose the method that best fits your needs. All of these methods will return a String
representation of the int
value.
Note that you can also use the +
operator to concatenate an int
value with a String
, but this is not recommended because it can lead to performance issues if used frequently.