Java Vector方法 add()与addElement()

来源:互联网 发布:国际数据统计公司 编辑:程序博客网 时间:2024/05/16 19:01
学渣看来只有返回值的区别,求讨论。
 /**     * Appends the specified element to the end of this Vector.     *     * @param e element to be appended to this Vector     * @return {@code true} (as specified by {@link Collection#add})     * @since 1.2     */    public synchronized boolean add(E e) {        modCount++;        ensureCapacityHelper(elementCount + 1);        elementData[elementCount++] = e;        return true;    }

  /**     * Adds the specified component to the end of this vector,     * increasing its size by one. The capacity of this vector is     * increased if its size becomes greater than its capacity.     *     * <p>This method is identical in functionality to the     * {@link #add(Object) add(E)}     * method (which is part of the {@link List} interface).     *     * @param   obj   the component to be added     */    public synchronized void addElement(E obj) {        modCount++;        ensureCapacityHelper(elementCount + 1);        elementData[elementCount++] = obj;    }

原创粉丝点击