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 primitive int example. Program to convert Java
- * String object to primitive int data type.
- */
- public class StringToInt {
- public static void main(String args[]){
- //new String object
- String str = new String("342");
- /*
- * To convert String to primitive int data type, use
- * parseInt(String) static method of Integer class
- */
- int i = Integer.parseInt(str);
- //this throws NumberFormatException for invalid number
- System.out.println("String converted to primitive int: " + i);
- }
- }

Post new comment