Dark Horse Programmer ———— List Collection of Java Collections (ii)

Source: Internet
Author: User

Features of the list collection:
Sequential (the elements stored and removed are identical), repeatable.

For example

Unique features of the list collection:
* A: Add features
* void Add (int index,object element): Adding elements at the specified location
* B: Get Features
* Object get (int index): Gets the element at the specified position
* C: List iterator
* Listiterator listiterator (): List collection-specific iterator
* D: Delete function
* Object Remove (int index): Deletes elements based on index, returns deleted elements
* E: Modify function
* Object Set (int index,object element): Modifies the element according to the index, returning the decorated element

Subclasses of the list collection

List: Elements are ordered and elements can be duplicated. Because the collection system has an index.

ArrayList: The underlying data structure uses an array structure. Features: Fast query speed. But additions and deletions are slightly slower. Thread is out of sync.

LinkedList: The underlying uses a linked list data structure. Features: Deletion speed quickly, query slightly slow.

Vector: The bottom layer is the array data structure. Thread synchronization. Replaced by the ArrayList.

LinkedList

LinkedList: The underlying uses a linked list data structure. Features: Deletion speed quickly, query slightly slow.

Unique methods:

1, increase

AddFirst ();

AddLast ();

2. Get

Gets the element, but does not delete the element. If there are no elements in the collection, Nosuchelementexception appears

GetFirst ();

GetLast ();

3. By deleting

Gets the element and deletes the element. If there are no elements in the collection, Nosuchelementexception appears

Removefirst ();

Removelast ();

After the JDK1.6, there was an alternative approach.

1, increase

Offfirst ();

Offlast ();

2. Get

Gets the element, but does not delete it. If there are no elements in the collection, NULL is returned.

Peekfirst ();

Peeklast ();

3. By deleting

Gets the element and deletes the element. If there are no elements in the collection, NULL is returned.

Pollfirst ();

Polllast ();

Dark Horse Programmer ———— List Collection of Java Collections (ii)

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.