How to convert int to String in Java
Example:
Input: num=1320
Output: "1320"
Approach: 1: Using toString()
Java
public class IntToString {public static void main(String[] args) {int num = 1320;String str = intToString(num);System.out.println("String is " + str);}private static String intToString(int num) {return Integer.toString(num);}}
Approach : 2: Using valueOf()
Java
public class IntToString {public static void main(String[] args) {int num = 1320;String str = intToString(num);System.out.println("String is " + str);}private static String intToString(int num) {return String.valueOf(num);}}
No comments:
Post a Comment