HTuse
Java ·
8 steps
How to Convert an String to Integer in Java?
Use `Integer.parseInt("123")`
Use `Integer.valueOf("123")`
Use `new Integer("123")`
Use `Integer.parseInt(str.trim())` for strings with surrounding spaces
Use `Integer.parseInt(str, 10)` for base-10 conversion
Use `Integer.parseInt(str, radix)` for other number bases
Use `try-catch` to handle `NumberFormatException`
Use `Integer.valueOf(str).intValue()` if you need a primitive `int` from `Integer`