Java Scrap Book  

Java Scrap Book > Data Type > String to Integer Conversion

String to Integer Conversion

You can convert String to Integer using either of two methods of Integer Wrapper Class.

  1. parseInt(String s)
  2. valueOf(String s)
  3. parseInt(String s ) and valueOf(String s) methods throws NumberFormatException excetion on wrong input


public class StringToInteger{

   public static void  main (String args[ ]){
    System.out.println(" String to Integer Conversion using parseInt method = " + Integer.parseInt("1234"));
    System.out.println("String to Integer Conversion using valueOf method = " + Integer.valueOf("345"));
    }
   }


OutPut
String to Integer Conversion using parseInt method = 1234
String to Integer Conversion using valueOf method = 345


Copyright © 2013-2017

javascrapbook.com is a computer science content service should not be treated as the publisher or speaker of any information provided by another Computer Science content provider.

Contact email: javascrapbook2013@gmail.com