Testing what a String token holds
- by Yiwei Gao
I am making a calculator and part of this program takes in user String input and tokenizes it (using my own implementation of a Tokenizer class). So now I have a bunch of Token objects and I would like to test each one of them to see if they hold numbers or operators.
Is there a way to test to see if they hold operators (ie. +, -, *, /, =, (, ), etc.) without using
if (token.equals("+") || token.equals("-") || ... and so on, for each operator? These Token objects are all of type String.