1. [ Java ] String to int
The static method Integer.parseInt will do the trick
There is a danger that the string does not represent a valid number in which case an exception will be raised.
There are plenty of similar routines such as:
Float.parseFloat Long.parseLong Double.parseDouble
Boolean.parseBoolean
2. [ Java ] Catch the exception
If the string is not a valid integer then an exception is raised.