Java-Vector__J2SE技術

來源:互聯網
上載者:User

對於List介面這裡還介紹一個它的實作類別Vector,Vector 類可以實現可增長的對象數組。 一、Vector簡介

        Vector可以實現可增長的對象數組。與數組一樣,它包含可以使用整數索引進行訪問的組件。不過,Vector的大小是可以增加或者減小的,以便適應建立Vector後進行添加或者刪除操作。

        Vector實現List介面,繼承AbstractList類,所以我們可以將其看做隊列,支援相關的添加、刪除、修改、遍曆等功能。

        Vector實現RandmoAccess介面,即提供了隨機訪問功能,提供提供快速存取功能。在Vector我們可以直接存取元素。

        Vector 實現了Cloneable介面,支援clone()方法,可以被複製。

[java]  view plain copy print ? public class Vector<E>       extends AbstractList<E>       implements List<E>, RandomAccess, Cloneable, java.io.Serializable  

        Vector提供了四個建構函式:

[java]  view plain copy print ? /**       * 構造一個空向量,使其內部資料數組的大小為 10,其標準容量增量為零。       */        public Vector() {               this(10);        }              /**       * 構造一個包含指定 collection 中的元素的向量,這些元素按其 collection 的迭代器返回元素的順序排列。       */       public Vector(Collection<? extends E> c) {           elementData = c.toArray();           elementCount = elementData.length;           // c.toArray might (incorrectly) not return Object[] (see 6260652)           if (elementData.getClass() != Object[].class)               elementData = Arrays.copyOf(elementData, elementCount,                       Object[].class);       }              /**       * 使用指定的初始容量和等於零的容量增量構造一個空向量。       */       public Vector(int initialCapacity) {           this(initialCapacity, 0);       }              /**       *  使用指定的初始容量和容量增量構造一個空的向量。       */       public Vector(int initialCapacity, int capacityIncrement) {           super();           if (initialCapacity < 0)               throw new IllegalArgumentException("Illegal Capacity: "+                                                  initialCapacity);           

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.