Java Program to convert an int value to String

Java 8Object Oriented ProgrammingProgramming

To convert an int value to String, use the toString() method in the following two ways.

Method 1

Example

 Live Demo

public class Demo {
   public static void main( String args[] ) {
      int val = 10;
      String str = Integer.toString(val);
      System.out.println("String: "+str);
   }
}

Output

String: 10

Let us see another example.

Method2

Example

 Live Demo

public class Demo {
   public static void main( String args[] ) {
      int val = 5;
      String str = new Integer(val).toString();
      System.out.println("String: "+str);
   }
}

Output

String: 5
raja
Published on 13-Nov-2018 07:08:33
Advertisements