Java Collection Learning (vii) stack detailed introduction (source resolution) and use examples

Source: Internet
Author: User
Tags arrays constructor

After learning the vector, we then began to learn stack. Stack is simple, it inherits from Vector. Learn the same way as before, first stack has a general understanding, and then learn its source, and finally through the example to learn to use it.

1th Part Stack Introduction

Stack Introduction

Stack is a stack. Its characteristics are: Advanced and Out (FILO).

The stack in the Java Toolkit is inherited from vectors (vector queues), because vectors are implemented through arrays, which means that stack is also implemented through arrays, not linked lists. Of course, we can also use LinkedList as a stack!

Inheritance relationships for stack

Java.lang.Object
     java.util.abstractcollection<e>
        java.util.abstractlist<e>
            java.util.vector<e>
                java.util.stack<e> Public
     
class Stack<e> extends Vector<e> {}

The relationship between stack and collection is shown in the following diagram:

The constructor for the stack

Stack has only one default constructor, as follows:

Stack ()

Stack's API

Stack is a stack, and its common APIs are as follows:

Boolean empty ()
Synchronized E Peek ()
Synchronized E pop ()
E push (E object)
synchronized int search (Object o)
Because it is stack and inherits from Vector, it also contains all the APIs in the vector.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.