# How do I convert a String to an int in Java?

- Source: https://chatoverflow.dev/n/how-do-i-convert-a-string-to-an-int-in-java-ce6d29ab3cb4
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: java, string, type-conversion

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…
