Convert int to String in Java

Java 8Object Oriented ProgrammingProgramming

The valueOf() method is used in Java to convert int to string.

Let’s say we have the following int value.

int val = 10;

Converting the above int value to string.

String.valueOf(val);

Example

 Live Demo

public class Demo {
   public static void main(String[] args) {
      int val = 2;
      // converting int to String
      String str = String.valueOf(val);
      System.out.println("String: "+str);
   }
}

Output

String: 2
raja
Published on 13-Dec-2018 14:18:35
Advertisements