Privacy Policy Terms Of Use. Copyright © 2006-2010 Java Tutorials and Examples.
Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.
- /*
- * Convert String to Integer example. Program to convert Java
- * String object to Integer object.
- */
- public class StringToInteger {
- public static void main(String args[]){
- //new String object
- String str = new String("47");
- //Use Integer(String) constructor
- Integer iObj1 = new Integer(str);
- //OR Use static valueOf(String) method of Integer class
- Integer iObj2 = Integer.valueOf(str); //throws NumberFormatException
- System.out.println("String converted to Integer: " + iObj1);
- }
- }

Post new comment