Need help with Java string issues… here is a solution to the problem.
Need help with Java string issues
I am developing a programmable calculator in Android. I take user input as a sequence of characters and then convert it to a string. But before putting them on the stack, I have to check if the input is an integer or a symbol.
I’m basically from a C++ background. So I had trouble finding the right features to do the job. Any help would be appreciated.
Solution
Two possible solutions:
- You can create a regex to check if your string is a number
- You can try extracting its integer value using the following methods
Integer.valueOf()
, and catch the exception [ NumberFormatException ] thrown – If it’s not
Number.
The first is most likely to be more efficient than the second