Reputation: 510
I'm trying to find a short way to write this (in Java) (note in this case top is a Node in a linkedlist)
if(top.data.equals("A") || top.data.equals("B") || top.data.equals("C") ||....)
postfix.push(pop());
My goal is something like
if(top.data.equals("A", "B", "C", "D", ....)
Is there a way to do this in Java? (I don't even know what to call it to do further research in the API and elsewhere).
Thanks for any help.
Upvotes: 1
Views: 1452
Reputation: 11947
if("ABC".indexOf(top.data.toString()) > -1){ .... }
Or
if("ABC".contains(top.data.toString())) { .... }
Upvotes: 0