zoukankan      html  css  js  c++  java
  • stack.isEmpty()和empty()

    public class Stack<E> extends Vector<E>
    可以看到Stack类继承了Vector类



    这个是stack类里面的方法:
     /**
         * Tests if this stack is empty.
         *
         * @return  <code>true</code> if and only if this stack contains
         *          no items; <code>false</code> otherwise.
         */
        public boolean empty() {
            return size() == 0;
        }
    调用了vector的size方法
     /**
         * Returns the number of components in this vector.
         *
         * @return  the number of components in this vector
         */
        public synchronized int size() {
            return elementCount;
        }
    vector的size方法返回elementCount

    这个是Vector的方法(线程安全的):

    /**
         * Tests if this vector has no components.
         *
         * @return  {@code true} if and only if this vector has
         *          no components, that is, its size is zero;
         *          {@code false} otherwise.
         */
        public synchronized boolean isEmpty() {
            return elementCount == 0;
        }

    可以看到二者没有区别,都是看elementCount 是否为0

  • 相关阅读:
    boot.asm
    C talk
    C 数据类型
    Locks, Deadlocks, and Synchronization
    C++的RTTI 观念和用途
    setup.asm
    驱动对象设备对象设备栈
    JNI 内存泄漏
    KMP 字符串匹配算法
    解开 Windows 下的临界区中的代码死锁
  • 原文地址:https://www.cnblogs.com/JohnTeslaaa/p/10597847.html
Copyright © 2011-2022 走看看