Advanced Java
Advanced Java
// Push operations
stack.push("John");
stack.push("Mary");
stack.push("Steve");
Stack operations go beyond merely push and pop. For example, to verify if
a stack is empty, we can use the empty() method. If it returns true, that
means the stack is empty. Conversely, if it returns false, we can infer the
stack is not empty. To peek at the top element of the stack without
popping it, we use the peek() method.
We will push all characters into a stack and then pop them out to get a
reversed string!
return reversedString.toString();
}