Advantages and disadvantages of several data structures in Java

Source: Internet
Author: User

Generally everyone knows the general difference between ArrayList and LinkedList:
1.ArrayList is the realization of the data structure based on dynamic array, LinkedList data structure based on linked list.
2. For random access get and set,arraylist feel better than LinkedList, because linkedlist to move the pointer.
3. Add and Remove,linedlist are the dominant for new and deleted operations because ArrayList is moving the data.
This point depends on the actual situation. If you insert or delete only a single piece of data, the ArrayList speed is better than LinkedList. But if bulk random insert deletes data, LinkedList speed is much better than ArrayList. Because ArrayList each insertion of data, you move the insertion point and all subsequent data.

4. Find Operation Indexof,lastindexof,contains and so on, both similar.
5. Randomly find the operation of the specified node get,arraylist faster than LinkedList.

Set is the simplest kind of collection. The objects in the collection are not sorted in a particular way, and there are no duplicate objects. The set interface mainly implements two implementation classes:

    • The Hashset:hashset class accesses the objects in the collection according to the hashing algorithm, and the access speed is relatively fast.
    • The Treeset:treeset class implements the SortedSet interface and is able to sort the objects in the collection.

Set usage: Holds reference to object, no duplicate object

A list is characterized by its elements being stored in a linear fashion, in which duplicate objects can be stored in the collection.

The main implementation classes of the list interface are:
    • ArrayList (): Represents the length can be changed by the group. Elements can be randomly accessed, and it is slow to insert and delete elements into ArrayList ().
    • LinkedList (): A linked list data structure is used in the implementation. Fast insertion and deletion, and slow access times.
For random access to a list, it is just random to retrieve the element at a particular location. The Get (int index) method of the List returns the object in the collection at the index location specified by the parameter index, starting with "0". The two most basic ways to retrieve all objects in a collection are:

Advantages and disadvantages of several data structures in Java

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.