I'm trying to push certain characters into a stack given:
public static double infixEvaluator(String line)
public static final String SPECIAL_CHARACTER = "()+-*/^";
Stack<String> operators = new Stack<String>();
I assumed I would run through the String with a for loop, then use if statements that would check whether the char at the index was a special character or a regular number
else if (SPECIAL_CHARACTER.contains(line)) {
char operator = line.charAt(i);
operators.push((String) operator);
}
Using this example: is there a way to add characters to a stack?
But I'm getting an error
cannot cast from char to string
I'm confused on why it's not allowing it to cast it?
if more code is needed let me know