Stack of java

1 Introduction

       Stack is a first-in-last-out data structure. It is a special linear table that can only perform related stacking and popping (acquisition) operations at one end, and supports storing the same elements and empty objects.

2. The main principle

       Stack in java is implemented internally through an array, and each operation is through an array operation. The defined array is an array of Object (Object[]), so every time an element is pushed into the stack or popped out of the stack is an operation Perform operations on the current Object array, and all operations are performed at the end of the array.

       Stack inherits Vector, the default size of Stack is 10, and the size cannot be initialized. The value of each expansion is twice the current stack size, because the default value of capacityIncrement is 0.

3. Push into the stack

Pushing into the stack-it is equivalent to putting data into the stack. Since the default stack size is 10, when there are more than 10 elements, the capacity needs to be expanded. The way to expand is to call Arrays.copyOf(elementData, newCapacity)

Guess you like

Origin blog.csdn.net/qq_38428623/article/details/102745346