How to convert String to Integer and Integer to String in Java?

Java 8Object Oriented ProgrammingProgramming

Java lang package provides Integer class which has methods to convert integer to String and vice versa. You can convert a String to an integer using the parseInt() method and Integer to String using the toString() method.

Example

 Live Demo

public class Sample {
   public static void main(String args[]) {
      String str = "1212";
      int num = Integer.parseInt(str);
      System.out.println(num);
      String st = Integer.toString(num);
      System.out.println();
   }
}

Output

1212
1212


raja
Published on 12-Feb-2018 09:54:06
Advertisements