Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need help in resolving Java String issues

I am developing a programmable calculator in android.I am getting user input in the form of charsequence which i then convert into string. But before i can put them in the stack i must check whether the input is an integer or a sign.

I am basically from a C++ background. So i am having issues finding the right functions to do the job. Any help would be appreciated.

like image 463
Some Body Avatar asked Apr 06 '26 21:04

Some Body


1 Answers

Two possible solutions:

  1. You can create a regex that checks if your string is a number
  2. You can try to extract its integer value using Integer.valueOf(), and catch the exception [NumberFormatException] thrown - if it is not a number.

The first is most likely to be more efficient then the second

like image 152
amit Avatar answered Apr 08 '26 09:04

amit