Search code examples
javaintegerstring-parsing

How to convert String to int and call method on it?


I have tried to convert my String to an int but my code keeps crashing.

The code is as follows:

String age = getAge();
CalculateDaysSinceBirth((int) age);

But I get a NumberFormatException.


Solution

  • Try using Integer.valueOf(age) insted of (int) age