美文网首页
Vector简介

Vector简介

作者: 加大装益达 | 来源:发表于2017-04-24 09:56 被阅读31次

Vector简介

  1. Vector和ArrayList类似,基于Object数组方式实现
  2. Vector是同步访问的,操作是线程安全的

源码分析

jdk1.7.0_71

//保存Vector中的元素
protected Object[] elementData;
//Vector中存储的元素个数
protected int elementCount;
//Vector容量自动增长的大小,此数值小于等于0,容量增长为2倍
protected int capacityIncrement;

Vector(int initialCapacity, int capacityIncrement) 初始容量和初始自动增长 构造

public Vector(int initialCapacity, int capacityIncrement){}

Vector(int initialCapacity) 初始容量 ,自动增长2倍 构造

public Vector(int initialCapacity){}

Vector() 初始容量10,自动增长2倍 构造

public Vector(){}

Vector(Collection<? extends E> c) 使用集合初始化

public Vector(Collection<? extends E> c){}

copyInto(Object[] anArray) 将Vector中的元素拷到Object数组中

public synchronized void copyInto(Object[] anArray) {}

trimToSize()

public synchronized void trimToSize() {} 

ensureCapacity(int minCapacity) 增加容量

public synchronized void ensureCapacity(int minCapacity) {}

grow(int minCapacity) 真正增长容量的方法

private void grow(int minCapacity) {}

setSize(int newSize) 设置大小

public synchronized void setSize(int newSize) {}

capacity() Vector的容量

public synchronized int capacity() {}

size() Vector包含元素的数量

public synchronized int size() {}

isEmpty()是否为空

public synchronized boolean isEmpty() {}

elements()返回一个枚举

public Enumeration<E> elements() {
            return new Enumeration<E>() {
            int count = 0;

            public boolean hasMoreElements() {
                return count < elementCount;
            }

            public E nextElement() {
                synchronized (Vector.this) {
                    if (count < elementCount) {
                        return elementData(count++);
                    }
                }
                throw new NoSuchElementException("Vector Enumeration");
            }
        };
}

contains(Object o) 是否包含指定元素

public boolean contains(Object o) {}

indexOf(Object o) 返回第一个匹配的索引

public int indexOf(Object o) {}

indexOf(Object o, int index) 返回第一个从index开始的匹配的Object

public synchronized int indexOf(Object o, int index){}

lastIndexOf(Object o) 返回最后一个匹配的索引

public synchronized int lastIndexOf(Object o) {}

lastIndexOf(Object o, int index)返回最后一个从index开始的匹配的Object

public synchronized int lastIndexOf(Object o, int index) {}

elementAt(int index) 返回指定位置的元素

public synchronized E elementAt(int index) {}

firstElement() 第一个元素

public synchronized E firstElement(){}

lastElement() 最后一个元素

public synchronized E lastElement() {}

setElementAt(E obj, int index) 设置指定位置的元素

public synchronized void setElementAt(E obj, int index) {}

removeElementAt(int index) 移除指定位置的元素

public synchronized void removeElementAt(int index) {}

insertElementAt(E obj,int index)指定位置之后插入元素

public synchronized void insertElementAt(E obj, int index) {}

addElement(E obj) 添加元素到最后

public synchronized void addElement(E obj) {}

removeElement(Object obj) 删除第一个匹配的元素

public synchronized boolean removeElement(Object obj) {}

removeAllElements() 删除所有元素

public synchronized void removeAllElements() {}

clone() 深拷贝

public synchronized Object clone() {}

toArray() 返回Object数组

public synchronized Object[] toArray() {}

toArray(T[] a) 返回指定类型的数组

public synchronized <T> T[] toArray(T[] a) {}

elementData(int index) 返回指定位置的元素

E elementData(int index) {}

get(int index) 获取指定位置的元素

public synchronized E get(int index) {}

set(int index, E element) 替换指定位置的元素

public synchronized E set(int index, E element) {}

add(E e) 添加元素到末尾

public synchronized boolean add(E e) {}

remove(Object o) 删除第一个匹配的元素

public boolean remove(Object o) {}

add(int index, E element) 指定位置后面插入元素

public void add(int index, E element){}

remove(int index) 删除指定位置的元素

public synchronized E remove(int index) {}

clear() 清空vector

public void clear() {}

containsAll(Collection<?> c) 是否包含指定的集合

public synchronized boolean containsAll(Collection<?> c) {}

addAll(Collection<? extends E> c) 把集合添加到vector的末尾

public synchronized boolean addAll(Collection<? extends E> c) {}

removeAll(Collection<?> c) 删除vector中所有的指定集合中的元素

public synchronized boolean removeAll(Collection<?> c) {}

retainAll(Collection<?> c)保留指定的集合元素,其他的删除

 public synchronized boolean retainAll(Collection<?> c) {}

addAll(int index, Collection<? extends E> c) 添加指定的集合元素到指定的位置之后

public synchronized boolean addAll(int index, Collection<? extends E> c) {}

equals(Object o)

public synchronized boolean equals(Object o) {}

hashCode()

public synchronized int hashCode() {}

toString()

public synchronized String toString() {}

subList(int fromIndex, int toIndex)返回一个子list

public synchronized List<E> subList(int fromIndex, int toIndex) {}

removeRange(int fromIndex, int toIndex) 删除指定区间的元素

protected synchronized void removeRange(int fromIndex, int toIndex) {}

listIterator(int index)/listIterator() 返回一个ListIterator

public synchronized ListIterator<E> listIterator(int index) {}

public synchronized ListIterator<E> listIterator() {
        return new ListItr(0);
    }

iterator() 返回一个Iterator

public synchronized Iterator<E> iterator() {
        return new Itr();
    }

参考

http://www.cnblogs.com/skywang12345/p/3308833.html

http://www.runoob.com/java/java-vector-class.html

相关文章

  • Vector简介

    Vector简介 Vector和ArrayList类似,基于Object数组方式实现 Vector是同步访问的,操...

  • Vector Clock 简介

    引言: 最近重读http://book.mixu.net/distsys/ebook.html,在分布式文件系统,...

  • Vector 源码分析

    Vector 简介 Vector 和 ArrayList 类似,顶级父类为 Collection,区别于 Arra...

  • 标准模板库-vector

    标准模板库-vector 1. vector简介 vector为C++的STL中的模板数组容器。在使用时需要包含#...

  • Java Collection框架 - Vector

    Java Collection框架 - Vector 基于jdk1.8 简介 Vector也是基于数组实现的动态数...

  • Vector

    Vector简介 Vector是一个矢量队列,继承于AbstractList,实现了List, RandomAcc...

  • Vector源码解析

    Vector简介 Vector也是基于数组实现的,是一个动态数组,其容量能自动增长。 Vector是JDK1.0引...

  • C++ STL标准库:std::vector 使用详解

    文章目录 简介 使用示例 构造、析构、赋值3.1 std::vector::vector 构造函数3.2 std:...

  • svm支持向量机

    1.1 svm简介 A Support Vector Machine (SVM) is a discriminat...

  • JDK源码分析(5)Vector

    JDK版本 Vector简介 首先,Vector 是一个可增长的数组(和 ArrayList 类似),能够用索引直...

网友评论

      本文标题:Vector简介

      本文链接:https://www.haomeiwen.com/subject/tbbuzttx.html