Java – string to int example

public class Main {
  public static void main(String[] args) {
    String str = "10";
    int i = Integer.parseInt(str);
    System.out.println("Integer after parsing: " + i);
    System.out.println("Now parsing string which is not integer");
    try {
      int j = Integer.parseInt("Not integer");
    } catch (Exception e) {
      e.printStackTrace(System.out);
    }
  }
}
OpenJDK 64-Bit Server VM warning: Insufficient space for shared memory file:
   1714
Try using the -Djava.io.tmpdir= option to select an alternate temp location.

Share this article: share on Google+ share on facebook share on linkedin tweet this submit to reddit

Comments

Click here to write/view comments