zoukankan      html  css  js  c++  java
  • vector

    vector和arrayList一样底层实现原理也是数组 区别: vector是同步的也就是线程安全的[因为vector里面的某些方法用了synchronized 关键字修饰,比如removeAll(),addAll(),equals(),Iterator()等方法被修饰]

    部分源码

      

    /**
    * Inserts all of the elements in the specified Collection into this
    * Vector at the specified position. Shifts the element currently at
    * that position (if any) and any subsequent elements to the right
    * (increases their indices). The new elements will appear in the Vector
    * in the order that they are returned by the specified Collection's
    * iterator.
    *
    * @param index index at which to insert the first element from the
    * specified collection
    * @param c elements to be inserted into this Vector
    * @return {@code true} if this Vector changed as a result of the call
    * @throws ArrayIndexOutOfBoundsException if the index is out of range
    * ({@code index < 0 || index > size()})
    * @throws NullPointerException if the specified collection is null
    * @since 1.2
    */
    public synchronized boolean addAll(int index, Collection<? extends E> c) {
    modCount++;
    if (index < 0 || index > elementCount)
    throw new ArrayIndexOutOfBoundsException(index);

    Object[] a = c.toArray();
    int numNew = a.length;
    ensureCapacityHelper(elementCount + numNew);

    int numMoved = elementCount - index;
    if (numMoved > 0)
    System.arraycopy(elementData, index, elementData, index + numNew,
    numMoved);

    System.arraycopy(a, 0, elementData, index, numNew);
    elementCount += numNew;
    return numNew != 0;
    }

    /**
    * Compares the specified Object with this Vector for equality. Returns
    * true if and only if the specified Object is also a List, both Lists
    * have the same size, and all corresponding pairs of elements in the two
    * Lists are <em>equal</em>. (Two elements {@code e1} and
    * {@code e2} are <em>equal</em> if {@code (e1==null ? e2==null :
    * e1.equals(e2))}.) In other words, two Lists are defined to be
    * equal if they contain the same elements in the same order.
    *
    * @param o the Object to be compared for equality with this Vector
    * @return true if the specified Object is equal to this Vector
    */
    public synchronized boolean equals(Object o) {
    return super.equals(o);
    }

    /**
    * Returns the hash code value for this Vector.
    */
    public synchronized int hashCode() {
    return super.hashCode();
    }

    /**
    * Returns a string representation of this Vector, containing
    * the String representation of each element.
    */
    public synchronized String toString() {
    return super.toString();
    }

  • 相关阅读:
    Access 通用访问类 OleDbHelper
    让Visual Studio 也支持JS代码折叠 [ Visual Studio | #region | #endregion ]
    提高网站性能的方法
    php 正则表达式整理 归纳 重点
    C++数据结构知识点
    algorithm算法设计,数据结构基本概念之我的归纳 by whb_咸菜圣斗士啊斌斌斌斌
    浏览器兼容性问题及常见的解决方法
    js抽象方法的使用
    js制作图片轮换切换
    C语言排序算法总结
  • 原文地址:https://www.cnblogs.com/zmblog/p/8691110.html
Copyright © 2011-2022 走看看