Vector中add和addelement的区别

来源:互联网 发布:北京金贵软件 编辑:程序博客网 时间:2024/06/06 09:58

Vector类里的add(Object o)和addElement(Object o)有什么区别呢

基本上没什么区别,add(Object o)是List接口中声明的方法,在Vector里实现。

还有就是,一个有返回值,一个没有返回值


public synchronized boolean add(E o) {
modCount++;
ensureCapacityHelper(elementCount + 1);
elementData[elementCount++] = o;
        return true;
    }



    public synchronized void addElement(E obj) {
modCount++;
ensureCapacityHelper(elementCount + 1);
elementData[elementCount++] = obj;
    }

原创粉丝点击