Testing what a String token holds

Posted by Yiwei Gao on Stack Overflow See other posts from Stack Overflow or by Yiwei Gao
Published on 2012-11-25T04:52:54Z Indexed on 2012/11/25 5:03 UTC
Read the original article Hit count: 153

Filed under:

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.

© Stack Overflow or respective owner

Related posts about java