FastFoodCoding

Login


Connect with one of the following accounts





Login

Please wait while we redirect...

Views: 311   



There are two ways you can convert a String into integer in Java

  1. Using Integer.parseInt(String input) - This returns primitive int
    String input = "123";
    int output = Integer.parseInt(input);
    System.out.println(output);
    
  2. Using Integer.valueOf(String input) - This returns cached instance of Integer type
    String input = "123";
    Integer output = Integer.valueOf(input);
    System.out.println(output);
    
    Note: Code will through NumberFormatException if you do not pass a valid number String.
    Ex. if you pass 123.23 that causes NumberFormatException.



On By


Top Tutorials

Top Questions

Top Articles

Top Blogs

Top News