Stack数据结构(jdk8)

Stack是基于Vector的一个FIFO的栈结构

    public E push(E item) {
        //添加元素
        addElement(item);
        return item;
    }

    public synchronized E pop() {
        E       obj;
        int     len = size();
        obj = peek();
        //删除最后一个元素(栈顶)
        removeElementAt(len - 1);
        return obj;
    }

    public synchronized E peek() {
        int     len = size();
        if (len == 0)
            throw new EmptyStackException();
        return elementAt(len - 1);
    }

原文地址:https://www.cnblogs.com/june777/p/11736584.html