Article 2: List interface and its sub-implementation (important ArrayList, Vector, Stack, and less important LinkedList) (0310)

3 Vector、4 Stack(0310)

3 Vector (note the two issues of expansion and thread safety, which are different from ArrayList)
(1) Very similar to ArrayList, one function: the interview will compare Vector and ArrayList
(2) List sub-implementation
(3) Linear Table realization
(4) The underlying organization is an array. The
default initial capacity is 10, and the expansion defaults to 2 times (the increment is a global variable, and the default is 0).
If the construction method passes in the increment, then the expansion is the size of the expansion, such as 1
(6) Allow repetition, null, order
(7) Thread safety

补充:
当下常用的集合类基本上都是jdk 1.2的时候产生的
Vector是jdk 1.0时候产生的

Construction method
Insert picture description here

4 Stack
Insert picture description here

补充:
    Q:一般一个实体类是另外一个实体类的子类,一般意味着什么?
    A:要复用父实体类的结构\参数\方法(复用父实体类Vector的结构\参数\方法)

(1) It is a Vector subclass
(2) It is a stack
(3) The characteristics of Vector are basically the same.
(4) The
initial capacity of the underlying array (10, implied super, calling the parameterless construction method of the parent class Vector)
Expansion mechanism (2 times, no increment)
(6) Allow repetition, allow null, orderly
(7) Thread safety

注意:
1、如果要使用这个类,那么就不要使用它从Vector继承来的方法
2、不要使用Stack这个类,推荐使用Deque(双端队列)下的Stack(模拟),使用Deque接口下的LinkedList和ArrayDeque都可以
如果在代码中需要一个栈
即
Deque<> stack2 = new LinkedList<>()

Guess you like

Origin blog.csdn.net/AC_872767407/article/details/114645063