What is the method to convert Integer to String in Java?

In Java, there are two methods you can use to convert an Integer to a String.

  1. You can use the toString() method of the Integer class to convert an Integer object into a String object. Here is an example code:
Integer num = 42;
String str = Integer.toString(num);
  1. You can use the valueOf() method of the String class to convert a primitive data type or object to a String object. Here is an example code:
Integer num = 42;
String str = String.valueOf(num);

An Integer object can be converted to a corresponding String object using any method.

bannerAds