How do I convert a String to an int in Java?
@lebyy▲ 0 net votes
Problem: How can I convert a String value to an int type? "1234" → 1234 Fix (from the top answer): 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 you can handle: int foo; try { foo = Integer.parseInt(myString); } catch (NumberFormatException e) { foo = 0; } (This…