I am trying to separate each word in a string and then add them to a stack. Here is the code I wrote to do this. Every time I run the tester, it always returns an empty stack, but shouldn't the stack have <body>
in it?
import java.util.Stack;
public class HTML3{
//main method
public static boolean checkBalance(String str) {
Stack<String> stack = new Stack<String>();
String[] words = str.split(" ");
for (int i = 0; i < words.length; i++) {
String tag = words[i];
if(tag=="<body>" || tag=="<hl>" || tag=="<center>" || tag=="<p>" || tag=="<ol>" || tag=="<li>") {
stack.push(tag);
}
}
return stack.isEmpty();
}
public static void main(String[]args)
{
checkBalance("<body> <li>");
}
}