Code example for Stack

Methods: empty, peek, pop, push

0
    public MenuComponent next() { 
        if (!hasNext()) { 
            return null; 
        } 
 
        Iterator<MenuComponent> iterator = stack.peek();
        MenuComponent component = iterator.next();
 
        if (component.hasChildren()) {
            stack.push(component.createIterator());
        } 
 
        return component;
    } 
 
    public boolean hasNext() { 
        if (stack.empty()) {
            return false; 
        } 
 
        Iterator iterator = stack.peek();
        if (iterator.hasNext()) {
            return true; 
        } 
 
        stack.pop();
        return hasNext(); 
    } 
 
    public void remove() { 
        throw new UnsupportedOperationException();