日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Vector源码分析

發布時間:2024/9/16 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Vector源码分析 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

?

import java.util.List; import java.util.Vector;public class VectorTest {public static void main(String[] args) {List<String> vector = new Vector<>();vector.add("abc");} }

查看Vector構造方法:

/*** Constructs an empty vector so that its internal data array* has size {@code 10} and its standard capacity increment is* zero.*/public Vector() {this(10);}

查看this(10)

/*** Constructs an empty vector with the specified initial capacity and* with its capacity increment equal to zero.** @param initialCapacity the initial capacity of the vector* @throws IllegalArgumentException if the specified initial capacity* is negative*/public Vector(int initialCapacity) {this(initialCapacity, 0);}

再繼續看this(initialCapacity,0)

/*** Constructs an empty vector with the specified initial capacity and* capacity increment.** @param initialCapacity the initial capacity of the vector* @param capacityIncrement the amount by which the capacity is* increased when the vector overflows* @throws IllegalArgumentException if the specified initial capacity* is negative*/public Vector(int initialCapacity, int capacityIncrement) {super();if (initialCapacity < 0)throw new IllegalArgumentException("Illegal Capacity: "+initialCapacity);this.elementData = new Object[initialCapacity];this.capacityIncrement = capacityIncrement;}

此時initialCapacity為10,capacityIncrement為0,this.elementData為對象數組

/*** The array buffer into which the components of the vector are* stored. The capacity of the vector is the length of this array buffer,* and is at least large enough to contain all the vector's elements.** <p>Any array elements following the last element in the Vector are null.** @serial*/protected Object[] elementData;

所以Vector底層采用的是數組來存放元素的,大部分的public方法都是synchronized的。即同步的。使用不當會造成性能問題。

Vector和ArrayList底層數據結構都是數組。

總結

以上是生活随笔為你收集整理的Vector源码分析的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。