Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

Converting Strings to Numbers and Vice Versa in Java.



Java lang package provides Integer class which has methods to convert an 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
Updated on: 2020-02-26T09:51:01+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements