How can we convert an integer to a string in Java?

In Java, there are two ways to convert integers to strings:

  1. Convert integer to string
int num = 123;
String str = Integer.toString(num);
  1. Convert to string.
int num = 123;
String str = String.valueOf(num);

Both methods can convert integers into their corresponding strings.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds