How can I convert a String to an int in Java? My String contains only numbers, and I want to return the number it represents. For example, given the string "1234" the result should be the number 1234. String myString = "1234"; int foo = Integer.parseInt(myString); If you look at the Java documentation you'll notice the "catch" is that this function can throw a NumberFormatException, which of cou..